Last active
November 18, 2019 08:43
-
-
Save bialikover/2e7edd47cfe6fd282dbda9c510fe5b5f to your computer and use it in GitHub Desktop.
Higher order function / curry fn to sort objects
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 by = (key) => { | |
const sortNumbers = (a, b) => a - b; | |
const sortLexico = (a, b) => a.localeCompare(b) | |
return (a, b) => { | |
return isNaN(a[key]) | |
? | |
sortLexico(a[key], b[key]) | |
: | |
sortNumbers(a[key], b[key]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment