could an option be added to the Sort() function so duplicated entries are removed? Something like:
Sort(array, unique)
For example, I have this code:
Code: Select all
mainDB = {
{category="Learning", name="Enrique", notes="Some notes.", modified="18-08-2022"},
{category="Shop", name="Ricardo", notes="Another note.", modified="10-09-2022"},
{category="Learning", name="Angel", notes="More notes.", modified="18-09-2022"},
{category="Mail", name="Roger", notes="Note.",modified="01-05-2022"},
{category="Accounts", name="Francisco", notes="Last note.", modified="18-09-2022"},
{category="Accounts", name="Rafael", notes="What note.",modified="27-08-2022"},
{category="Learning", name="Jordi", notes="My note.",modified="11-06-2022"},
}
categoryList = {}
Function p_GetCategories()
Local tempCategories = {}
;save category from each record in temporary array
For i = 0 To (TableItems(mainDB) - 1)
Local item = (mainDB[i].category)
InsertItem(tempCategories, item)
Next
;sort temporary array
Sort(tempCategories)
;save first record from temporary to final category array
InsertItem(categoryList, tempCategories[0])
;compare remaining temporary records with the previous record
;in the final array and insert it if it's different
For i = 1 To (TableItems(tempCategories)-1)
If tempCategories[i] <> tempCategories[i-1] Then InsertItem(categoryList, tempCategories[i])
Next
EndFunction
ForEachI(categoryList, DebugPrint)
Code: Select all
0 Accounts
1 Learning
2 Mail
3 Shop