Created
November 21, 2018 23:41
-
-
Save iaindooley/5d2cc46bd6d91c4605c5ed532a82a2c9 to your computer and use it in GitHub Desktop.
Sort lists numerically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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