# Sorting subarrays using map function

Sorting subarrays using map function
0

#1
``````function largestOfFour(arr) {
// use the map function to sort each array big to small. Return the 1st value.

arr = arr.map (function(x) {
x = arr.sort (a, b)
{
var sort = b - a;
return sort;

}
});

var largest_numbers = [];

for (i = 0; i < arr.length; i++) {
var index_zero_numbers = arr[i][0];
largest_numbers = largest_numbers.push[index_zero_numbers];
}

return largest_numbers;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
``````

Anyone see the problem?

#2

callback function!

check THIS page for example of usage sort() method. That’s not maybe the exact problem or solution but when I run your code in jsfiddle i saw that error in console!

#3

when you use .sort() whatever you put in () needs to be a function; also, sort would not be a var. so instead of

``````
x = arr.sort (a, b)
{
var sort = b - a;
return sort;

``````

…you would:

``````
x = arr.sort(function(a, b) { return b - a; })

``````