So I have question where I am given an array of arrays like this.
Array = [ [2,5,1], [1,23], [3], [22,16,8] ]
I have to order the sub arrays from smallest to largest based on the largest value in the array. So that top array becomes:
[ [3], [2,5,1], [22,16,8], [1,23] ]
I have to create two functions, one to find the max value of an array, and one that gets put into the following method.
x.sort(method) would result in the answer above.
I created a method to find the max value in an array which is here.
function fidMax(array){
copy = array.sort(function(a,b){return a-b})
return copy[copy.length-1]
}
It just sorts the array, and returns the last element.
Now I want to make my second method which uses reduce.
function compare(array){
array.reduce(findMax)
}
I have that, but it is NOT working, it won't even compile, and I am not sure why. I have to use the findMax() method in the compare() method, and the compare() method MUST use reduce().
Any ideas on what to do?
Thanks.
.reducethere at all: just sort by the largest value.comparefunction is supposed to return? (you have not explained it anywhere)