Last active
April 11, 2016 19:37
-
-
Save sanex3339/d0b633c1ad4b17e295ec884d3927e3cb to your computer and use it in GitHub Desktop.
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
export function ArraySortBy <T> (array: T[], getProperty: (value: T) => any): T[] { | |
return array.sort((a, b) => { | |
let aValue: any = getProperty(a), | |
bValue: any = getProperty(b); | |
if (aValue === undefined || bValue === undefined) { | |
return 0; | |
} | |
return (aValue > bValue ) ? 1 : ((bValue > aValue) ? -1 : 0); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment