I'm trying to return the largest number in every array to one array with sort() method. I think I did the whole code correctly except sorting:
function largestOfFour(arr) {
let result=[];
for(let i=0; i < arr.length; i++) {
for(let j=0; j < arr[i].length; j++) {
let segregatedArr = arr[0][j].sort((a,b)=>b-a);
}
result = segregatedArr[0][i][0];
}
return result;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
And I'm getting an error:
TypeError: arr[0][j].sort is not a function
I was trying the slice method or mapping to an array with:
result = $.map(arr, function(value, index) { return [value]; });
result.sort().reverse();
But the error was still the same in both cases.
arrarray you're passing to the function, otherwise you'll add a layer of complexity to your question: people have to suppose what you're trying to do before providing any help.