JS question: Return largest numbers in arrays

Why is var sb = 1 here, and not var sb = 0?:

function largestOfFour(arr) {
  var results = [];
  for (var n = 0; n < arr.length; n++) {
    var largestNumber = arr[n][0];
    for (var sb = 1; sb < arr[n].length; sb++) {
      if (arr[n][sb] > largestNumber) {
        largestNumber = arr[n][sb];

    results[n] = largestNumber;

  return results;

Referring to this lesson:

Because arr[n][0] has already been assigned to largestNumber.


Thanks so much. Makes sense!

Iā€™m glad I could help. Happy coding!

Your code has been blurred out to avoid spoiling a full working solution for other campers who may not yet want to see a complete solution. In the future, if you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

Thank you.

1 Like