-
-
Save seckBalla/117548eda7d06810063bef22d8986afe to your computer and use it in GitHub Desktop.
Example of functional sorting an object array by name and age
This file contains hidden or 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