Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. function sortByThenBy(arr, props) {
  2. // apply custom sort function on array
  3. return arr.sort(function(a, b) {
  4. // generate compare function return value by
  5. // iterating over the properties array
  6. return props.reduce(function(bool, k) {
  7. // if previous compare result is `0` then compare
  8. // with the next property value and return result
  9. return bool || (a[k] - b[k]);
  10. // set initial value as 0
  11. }, 0);
  12. })
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement