# Return Largest Numbers in Arrays - not passing

**URL:** <https://forum.freecodecamp.org/t/return-largest-numbers-in-arrays-not-passing/319652>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [October 5, 2019, 2:36pm UTC](https://forum.freecodecamp.org/t/return-largest-numbers-in-arrays-not-passing/319652 "2019-10-05T14:36:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![free4mOriginal](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/free4moriginal/32/127669_2.png) [@free4mOriginal](https://forum.freecodecamp.org/u/free4mOriginal)\
**Post date:** [October 5, 2019, 2:36pm UTC](https://forum.freecodecamp.org/t/return-largest-numbers-in-arrays-not-passing/319652/1 "2019-10-05T14:36:43Z")

</div>

**Tell us what’s happening:**

I don’t understand why this code is not passing, in repl.it it works fine and returns an array of largest numbers from each sub-array.

**Your code so far**

```js

function largestOfFour(arr) {
  let tempArr = [];
  for (let i=0; i<arr.length; i++) {
    let count = 0;
    for (let j=0; j<arr[i].length; j++) if (arr[i][j] > count) count = arr[i][j];
    tempArr.push(count);
  }
  return tempArr;
}

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 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36`.

**Link to the challenge:**

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/return-largest-numbers-in-arrays)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [October 5, 2019, 2:41pm UTC](https://forum.freecodecamp.org/t/return-largest-numbers-in-arrays-not-passing/319652/2 "2019-10-05T14:41:28Z")

</div>

it would be really useful if you would say what errors you get, otherwise it is just guessing.

> [@free4mOriginal](#):
>
> `for (let j=0; j<arr[i].length; j++) if (arr[i][j] > count) count = arr[i][j];`

break this down, too many things on the same line. this is giving one error in the freecodecamp editor.

second… what happen when the largest number is smaller then 0?

---

<div class="post-metadata">

**Author:** ![free4mOriginal](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/free4moriginal/32/127669_2.png) [@free4mOriginal](https://forum.freecodecamp.org/u/free4mOriginal)\
**Post date:** [October 5, 2019, 2:46pm UTC](https://forum.freecodecamp.org/t/return-largest-numbers-in-arrays-not-passing/319652/3 "2019-10-05T14:46:24Z")

</div>

Yes, you’re right about the negative numbers, I didn’t account for that, I will refactor. But with all positive numbers I don’t get any errors when I run it in repl.it, but freeCodeCamp editor gives me a `TypeError: unknown: Cannot read property '0' of undefined` error.

UPDATE  
Oh, I see what you mean. That’s weird, I use one-liners all the time, never had a problem with it.

UPDATE 2  
Just had to change the count assignment line, everything works with the negative numbers, too now:  
`let count = arr[i][0];`

Thanks!

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 25, 2021, 11:58am UTC](https://forum.freecodecamp.org/t/return-largest-numbers-in-arrays-not-passing/319652/4 "2021-01-25T11:58:47Z")

</div>


