This was the challenge:
Return Largest Numbers in Arrays
Return an array consisting of the largest number from each provided sub-array. For simplicity, the provided array will contain exactly 4 sub-arrays.
Remember, you can iterate through an array with a simple for loop, and access each member with array syntax arr[i]
.
Here is my solution:
function largestOfFour(arr) {
let ans = []
for(let i = 0; i < arr.length; i++){
let x = arr[i]
ans.push(x.reduce(function(long, index){return Math.max(long,index)}))
}
return ans;
}
console.log(largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]))
I am asking because after solving I checked the solutions provided and did not see this type of solution there. In fact, none of them used the reducer. Any critique, insight, feedback is what I am looking for.
Thanks!