Skip to content

Instantly share code, notes, and snippets.

@squarelabsgit
Created June 30, 2023 21:00
Show Gist options
  • Select an option

  • Save squarelabsgit/fe90e21e3db23bb17ab84ad9546a5c53 to your computer and use it in GitHub Desktop.

Select an option

Save squarelabsgit/fe90e21e3db23bb17ab84ad9546a5c53 to your computer and use it in GitHub Desktop.
Sorting Maps - Code

Deluge Example Code

//The unsorted list word be your source data
unsortedList = [{},{}...];
//Required Variables
unsortedKeys = List();
unsortedKeyValueData = Map();
sortedList = List();
//Go through each item in the list
for each item in unsortedList
{
    //Get the value to sort with and add unique value on the end
    sortingValue = item.get("Due_Date") + "-" + item.get("id");
    //Add the sorting value to a list
    unsortedKeys.add(sortingValue);
    //Add the sorting value to the unsorted key value map as the key & the item data as the value
    unsortedKeyValueData.put(sortingValue,item);
}
//Sort the keys
sortedKeys = unsortedKeys.sort(true);
//Compile the sorted list in order by going through each key and adding them to a new list.
for each  key in sortedKeys
{
    sortedList.add(unsortedKeyValueData.get(key));
}
//Now do whatever you want with your sorted list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment