Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const nestedArray = [ [ 'm', 1 ], [ 'i', 4 ], [ 's', 4 ], [ 'p', 2 ] ];
- function descNumbersAscChar(arrA, arrB) {
- if (arrA[1] > arrB[1]) { return -1 }
- else if (arrA[1] === arrB[1]) {
- if (arrA[0] < arrB[0]) { return -1 }
- else if (arrA[0] > arrB[0]) { return 1}
- }
- else if (arrA[1] < arrB[1]) { return 1 }
- else {
- console.log('Uncaught situation!')
- return 1
- }
- };
- console.log(nestedArray.sort(descNumbersAscChar)); // [ [ 'i', 4 ], [ 's', 4 ], [ 'p', 2 ], [ 'm', 1 ] ]
Add Comment
Please, Sign In to add comment