I'm practicing using the map method and i'm stuck on this problem. I'm trying to return the largest number out of each of these arrays but for my function to be complete i need to return the push method outside of my nested map. I have no idea how to do that. Any input would be extremely appreciated. Thanks in advance.
const bigAssArr = [[4, 5, 1, 3], [13, 27, 18 , 26], [32, 35, 37, 39], [100, 1001, 857, 1]]
const biggestFour = [];
const largestOfFour = (arr) => {
return arr.map((item, index) => {
let tempMax = item[0];
return item.map((i, iTwo) => {
let currentValue = i;
if (currentValue > tempMax ) {
tempMax = currentValue
}
})
biggestFour.push(tempMax); // *** This is where i'm having the problem***
})
}
arr.map(x => Math.max(...x)).mapis the wrong solution..mapreturns an array of the same length with the same or different values after transforming them;.filterreturns an array of the same or less length based on a predicate, and.reducetakes an array and an initial value and returns whatever you want (reduce is very flexible). That's why your outer map is reasonable, but the inner map doesn't make any sense.Math.max(...arr)has an issue. So pls take a look at the second solution of mine. Thanks ^^!