Build the Largest Number Finder - Build the Largest Number Finder

Tell us what’s happening:

looking to see if how I am doing this is the correct way. Even though it passed, I feel like using the -Infinity tag is not the correct way

Your code so far

function largestOfAll(arr) {
  let lrgArr = [];

  for (let i = 0; i < arr.length; i++) {
    let temp = arr[i];
    let x = -Infinity;
    for (let j = 0; j < temp.length; j++) {
      if (temp[j] > x) {
        x = temp[j]
      }
    } lrgArr.push(x);
  }
  return lrgArr;
}

console.log(largestOfAll([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]))

console.log(largestOfAll([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]))


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36

Challenge Information:

Build the Largest Number Finder - Build the Largest Number Finder

Why is that?

If it works it seems correct?

the console would always suggest iterating from the first value in each sub array but I couldn’t figure out how to do that

It did ? Can you show me an example please?

You couldn’t? Can you please explain how your code works briefly?

How is this related to using -Infinity ?

actually nevermind, that was from another forum post I was reading. My bad

Why did you use -Infinity?

What problem did it solve for you?

Can you explain what this for loop is for?

infinity solved the issue of not finding negative numbers.

the j variable iterated through the sub arrays

And it iterates from the first value of each sub array, correct? Seems like you did figure that out?

Did you see a different approach in the forum that you have a question about?

no I think I just got confused, remembering everything is very tough for me :melting_face:

Thanks pkdvalis!

1 Like