# Need some hint for this quiz )

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/return-largest-numbers-in-arrays/

my code :

``````function largestOfFour(arr) {
let firsNumArr1 = arr[0][0];
let firsNumArr2 = arr[1][0];
let firsNumArr3 = arr[2][0];
let firsNumAar4 = arr[3][0];

console.log(firsNum);
for (let i = 0; i < arr.length; i++){
for (let j = 0 ; j < arr[i].length ; j++ ){

}
}

// You can do this!
return arr;
}

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

While you can use two indexes for this one, you really donât need to. The same as the last time, map out the logic first. You know youâre getting an array containing four members, each of which is an array. You know, from each of those four, you are asked to find the largest number, and store that for later. Letâs seeâŚ

• create a variable to hold an array of largest values
• loop through the outer array (the one containing the sub-arrays).
• push that largest value onto the variable we created at step one.
• finish looping over all the arrays
• return the array of largest values in each array.

Thanks for helping ) I write code by your plan but code ruturn NaN (

``````function largestOfFour(arr) {
// You can do this!
let myArr = [];
for ( let i = 0; i < arr.length; i++ ){
myArr.push(Math.max(arr[i]));
}
console.log(myArr);

return arr;
}

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

perhaps Math.max() must be not in push function ?

`Math.max` is fine in the push function. The issue is, what youâre feeding into `Math.max()`. It doesnât know how to take an array of values and use each one as a parameter.

You know the sub-array will have four members, so each could be found by `arr[i][0]` (the first number in the i-th array), `arr[i][1]` etc. So youâd have to put each of these into `Math.max()` explicitly.

Hey! In that Math.max page I sent, thereâs a section on âgetting the maximum number from an arrayâ - take a look at that, it might help.

Research research research.

1 Like

Iâm just amazed how easy it can be) I miss your logic)) thanks for the help)

Now Iâm not gonna keep giving you the logic outline like that - next time I want to see you show us one!

It will be hard )
perhaps this is the real work of the programmer, display your logic using the programming language

The ârealâ programming is maybe ten percent programming. Mostly, itâs researching, and mapping flow, and trying to figure pitfalls before they become a problem.

And, of course, fixing bugs.

you went through the camp to the end ?

Nah. Some of it, some Iâm still going. Kind of got un-motivated, and decided to coach for a while and work on some personal projects.