Skip to content

Instantly share code, notes, and snippets.

@ayoola-solomon
Created June 27, 2017 17:21
Show Gist options
  • Save ayoola-solomon/339e40ce4587afcfb235cd9cadabb73f to your computer and use it in GitHub Desktop.
Save ayoola-solomon/339e40ce4587afcfb235cd9cadabb73f to your computer and use it in GitHub Desktop.
Smava SortUsers created by Soulman - https://repl.it/JEGC/7
function usersComparator(userA, userB) {
if (userA.active !== userB.active) {
return userA.active - userB.active
}
if(userA.registrationDate !== userB.registrationDate) {
return userA.registrationDate - userB.registrationDate;
}
return userA.requestedAmount - userB.requestedAmount;
}
function sortUsers(users) {
return users.sort(usersComparator);
}
var data = [
{id: 2, active: false, registrationDate: new Date(2016, 11, 1), requestedAmount: 10000},
{id: 1, active: false, registrationDate: new Date(2016, 10, 15), requestedAmount: 5000},
{id: 3, active: true, registrationDate: new Date(2016, 10, 14), requestedAmount: 5000},
{id: 5, active: true, registrationDate: new Date(2017, 0, 2), requestedAmount: 5000},
{id: 4, active: true, registrationDate: new Date(2016, 10, 14), requestedAmount: 5500},
];
sortUsers(data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment