Skip to content

Instantly share code, notes, and snippets.

@iaindooley
Created November 21, 2018 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iaindooley/5d2cc46bd6d91c4605c5ed532a82a2c9 to your computer and use it in GitHub Desktop.
Save iaindooley/5d2cc46bd6d91c4605c5ed532a82a2c9 to your computer and use it in GitHub Desktop.
Sort lists numerically
function sortListByNameNumerically(notification)
{
var added_card = new Notification(notification).addedCard();
if(added_card.name() != "Sort")
throw new InvalidActionException("No sorting requested");
var list = added_card.archive().currentList();
var sorted = list
.cards()
.asArray();
sorted.sort(function(card1,card2)
{
return parseInt(card1.name()) - parseInt(card2.name());
});
new IterableCollection(sorted).each(function(item,key)
{
if(!key)
key = "top";
item.moveToList(list,key);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment