Skip to content

Instantly share code, notes, and snippets.

@sanex3339
Last active April 11, 2016 19:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanex3339/d0b633c1ad4b17e295ec884d3927e3cb to your computer and use it in GitHub Desktop.
Save sanex3339/d0b633c1ad4b17e295ec884d3927e3cb to your computer and use it in GitHub Desktop.
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