Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sortByThenBy(arr, props) {
- // apply custom sort function on array
- return arr.sort(function(a, b) {
- // generate compare function return value by
- // iterating over the properties array
- return props.reduce(function(bool, k) {
- // if previous compare result is `0` then compare
- // with the next property value and return result
- return bool || (a[k] - b[k]);
- // set initial value as 0
- }, 0);
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement