so I’ve been working on this for two days now and it is supposed to be simple to do, so why am I still struggling.
A baby elephant was stuck in the mud. Mama couldn’t get him out 'cause she could not reach.
She saw a tree nearby and ran for it. She returned with a branch. That was longer than the pit of mud. The baby gladly grabs the branch and gets out to the safety of his Mama.
Guys, I need a branch.
Your code so far
function largestOfFour(arr) {
// You can do this!
var answer = [];
//assigns an empty answer
var i = 0
/* assigns i to 0 for first position
i took it out of the loop cause var in the loop confused me.*/
for (; i < arr.length; i++){
// this is the loop
var largestNumber = arr[i][0];
// assigns arr to i and the sub array
for (var sb = 1; sb < arr[i].length; sb++) {
//another loop
if (arr[i][sb] > largestNumber) {
/* if both arrays or bigger than the largestNumber
than the largest number is than to be that number.
So then my answer is 5 I don't understand.It shoulded be 5.*/
largestNumber = arr[i][sb];
answer = largestNumber;
}
} return answer;
}
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/return-largest-numbers-in-arrays