# Returning Largest Numbers in Arrays CHALLENGE

Hey guys, I’m struggling with this algorithm challenge. Am I close or way off base here?

As soon as a `return` statement is reached, no further code is executed. In other words, `return largeNum` on line 11 means that your function returns that single number and it’s all over.

Ahh Okay. Thank you @rmdawson71! What you said makes sense. I moved line 11 to line 10 and changed it to push largeNum to newArr instead of returning, and moved largeNum to right before my nested loop. I’m confused as to what I should assign to it though since, as you said, the logic fails with negative values–I just left empty quotes? But this code is still not passing the challenge. When I look at the console output, it’s pushing the TWO highest values of each subarray to the newArr instead of one?

``````function largestOfFour(arr) {
// You can do this!
var newArr = [];
for (var i = 0; i < arr.length; i++) {
var largeNum = '';
for (var j = 0; j < arr[i].length; j++) {
if (arr[i][j] > largeNum) {
largeNum = arr[i][j];
newArr.push(largeNum);
}

}
}
return newArr;
}

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

Okay, I fixed it! Please school me on those best practices haha.

``````function largestOfFour(arr) {
// You can do this!
var newArr = [];

for (var i = 0; i < arr.length; i++) {
var largeNum = 0;
for (var j = 0; j < arr[i].length; j++) {
if (arr[i][j] > largeNum) {
largeNum = arr[i][j];

}

} newArr.push(largeNum);
}
return newArr;
}

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