Guest User

Untitled

a guest
Dec 10th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. const nestedArray = [ [ 'm', 1 ], [ 'i', 4 ], [ 's', 4 ], [ 'p', 2 ] ];
  2.  
  3. function descNumbersAscChar(arrA, arrB) {
  4. if (arrA[1] > arrB[1]) { return -1 }
  5. else if (arrA[1] === arrB[1]) {
  6. if (arrA[0] < arrB[0]) { return -1 }
  7. else if (arrA[0] > arrB[0]) { return 1}
  8. }
  9. else if (arrA[1] < arrB[1]) { return 1 }
  10. else {
  11. console.log('Uncaught situation!')
  12. return 1
  13. }
  14. };
  15.  
  16. console.log(nestedArray.sort(descNumbersAscChar)); // [ [ 'i', 4 ], [ 's', 4 ], [ 'p', 2 ], [ 'm', 1 ] ]
Add Comment
Please, Sign In to add comment