Seeking help with sorting a multidimensional array in JavaScript to return it in descending order.
Here is the input:
let input = [[1,2,3],[1,3,2],[3,2,1],[3,1,2],[2,1,3],[2,3,1]]
Expected Output:
[[3,2,1],[3,1,2],[2,3,1],[2,1,3],[1,3,2],[1,2,3]]
I have attempted using the sort method:
let result = input.sort((a, b) => a - b)
However, I keep receiving the original array as output:
[[1,2,3],[1,3,2],[3,2,1],[3,1,2],[2,1,3],[2,3,1]]
I also tried using a for loop with the sort method:
for(let i = 0; i < input.length; i++){
let inputArr = input[i]
let output = inputArr.sort((a,b) => a - b)
console.log(output)
}
Yet, I am getting back [1,2,3] six times (the length of the original array). How can I achieve the desired descending order?
Appreciate any guidance. Thanks!