Skip to content

Instantly share code, notes, and snippets.

@seckBalla
Created November 2, 2018 14:23
Show Gist options
  • Save seckBalla/6207ec5b0a29dc26c79888adc3711f2d to your computer and use it in GitHub Desktop.
Save seckBalla/6207ec5b0a29dc26c79888adc3711f2d to your computer and use it in GitHub Desktop.
Example of functional sorting an object array by name and age
const persons = [
{ 'name':'luke', 'age':10},
{ 'name':'leia', 'age':10},
{ 'name':'vader', 'age':40}
];
const ascending = x => y => x > y;
const ageSort = (x, y) => ascending(x.age)(y.age);
const nameSort = (x, y) => ascending(x.name)(y.name);
const ascendingSort = persons.sort(nameSort).sort(ageSort);
console.log(ascendingSort);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment