Guest User

Untitled

a guest
Dec 17th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. /**
  2. * Returns an array of objects sorted a-z by prop.
  3. *
  4. * @prop array arr An array of objects.
  5. * @prop array props An array of props to sort against.
  6. * @return array A copy of arr sorted by prop.
  7. */
  8. export function sortObjectsAz(arr: Array<Object>, props: Array<string>): Array<Object> {
  9. if (arr.length < 1 || props.length < 1) return arr;
  10.  
  11. return [].concat(arr).sort((a, b) => {
  12. var labelA = getSortProp(a, props);
  13. var labelB = getSortProp(b, props);
  14. return (labelA < labelB) ? -1 : (labelA > labelB) ? 1 : 0;
  15. });
  16. }
Add Comment
Please, Sign In to add comment