Created
November 2, 2018 14:23
-
-
Save seckBalla/6207ec5b0a29dc26c79888adc3711f2d to your computer and use it in GitHub Desktop.
Example of functional sorting an object array by name and age
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
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