and I have been able to get the code to return an array, but it is filled with the two highest numbers of each sub-array rather than just the single highest number. my code follows:
function largestOfFour(arr) {
let sorted = [];
for (let i = 0; i < arr.length; i++) {
let arrInner = arr[i];
for (let j = 0; j < arrInner.length; j++) {
sorted.push(arrInner.sort().pop());
}
} return sorted;
}
console.log(largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]));
so I am getting [5,4,27,26,39,37,857,1001] rather than [5, 27, 39, 1001].
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.
See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.
Hey I figured it out, thanks for cluing me in on that unnecessary inner loop! That really got the ball rolling. I ended up running a function inside of sort() as follows:
sorted.push(arrInner.sort(function( a, b) {return a - b}).pop());
This “sorted” (pun totally intended) the rest of the code out and now it is working. Thanks all for your input!