Guest User

Untitled

a guest
Nov 17th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  1. /*
  2. * Usage:
  3. * const sortedArray = arrayOfObjects.sort((a, b) => compareTwoObjectsByField(a, b, 'fieldName'));
  4. */
  5. export function compareTwoObjectsByField(a, b, field) {
  6. if (a[field] < b[field]) {
  7. return -1;
  8. } else if (a[field] > b[field]) {
  9. return 1;
  10. }
  11. return 0;
  12. }
Add Comment
Please, Sign In to add comment