Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Returns an array of objects sorted a-z by prop.
- *
- * @prop array arr An array of objects.
- * @prop array props An array of props to sort against.
- * @return array A copy of arr sorted by prop.
- */
- export function sortObjectsAz(arr: Array<Object>, props: Array<string>): Array<Object> {
- if (arr.length < 1 || props.length < 1) return arr;
- return [].concat(arr).sort((a, b) => {
- var labelA = getSortProp(a, props);
- var labelB = getSortProp(b, props);
- return (labelA < labelB) ? -1 : (labelA > labelB) ? 1 : 0;
- });
- }
Add Comment
Please, Sign In to add comment