Created
May 11, 2017 03:54
-
-
Save ideosyncretic/17f6b3274ff3cd120ddf104384c6993a to your computer and use it in GitHub Desktop.
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
function predicateBy(prop){ | |
return function(a,b){ | |
if( a[prop] > b[prop]){ | |
return 1; | |
}else if( a[prop] < b[prop] ){ | |
return -1; | |
} | |
return 0; | |
} | |
} | |
//Usage | |
yourArray.sort( predicateBy("age") ); | |
yourArray.sort( predicateBy("name") ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment