# Basic Algorithm Scripting - Return Largest Numbers in Arrays

**URL:** <https://forum.freecodecamp.org/t/basic-algorithm-scripting-return-largest-numbers-in-arrays/583958>\
**Category:** I Built This\
**Created:** [January 10, 2023, 9:13am UTC](https://forum.freecodecamp.org/t/basic-algorithm-scripting-return-largest-numbers-in-arrays/583958 "2023-01-10T09:13:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jc-padua](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jc-padua/32/275636_2.png) [@jc-padua](https://forum.freecodecamp.org/u/jc-padua)\
**Post date:** [January 10, 2023, 9:13am UTC](https://forum.freecodecamp.org/t/basic-algorithm-scripting-return-largest-numbers-in-arrays/583958/1 "2023-01-10T09:13:20Z")

</div>

**Tell us what’s happening:**

This solution completed the challenge, but I don’t think it was a good answer. Can someone tell me about the flaws in the way I code?

**Your code so far**

```javascript
function largestOfFour(arr) {
  let result = []
  for (let i = 0; i < arr.length; i++) {
    for (let j = 0; j < arr[i].length; j++) {
      result.push(Math.max(...arr[i]))
      break;
    }
  }
  return result;
}

const output = largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
console.log(output)

```

**Challenge:** Basic Algorithm Scripting - Return Largest Numbers in Arrays

**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:** ![sanity](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sanity/32/378897_2.png) [@sanity](https://forum.freecodecamp.org/u/sanity)\
**Post date:** [January 10, 2023, 9:24am UTC](https://forum.freecodecamp.org/t/basic-algorithm-scripting-return-largest-numbers-in-arrays/583958/2 "2023-01-10T09:24:28Z")

</div>

Why exactly do you think it’s not a good answer? Do you have some specific concerns? Answering yourself these questions can give you something concrete to focus on.

---

<div class="post-metadata">

**Author:** ![jc-padua](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jc-padua/32/275636_2.png) [@jc-padua](https://forum.freecodecamp.org/u/jc-padua)\
**Post date:** [January 10, 2023, 9:58am UTC](https://forum.freecodecamp.org/t/basic-algorithm-scripting-return-largest-numbers-in-arrays/583958/3 "2023-01-10T09:58:02Z")

</div>

I think the way I came up with that solution shows I’m not that confident in my answer, though we all know there is no perfect answer or code. I feel it was not enough, or there is something wrong with it.

---

<div class="post-metadata">

**Author:** ![hbar1st](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/hbar1st/32/372649_2.png) [@hbar1st](https://forum.freecodecamp.org/u/hbar1st)\
**Post date:** [January 10, 2023, 10:56am UTC](https://forum.freecodecamp.org/t/basic-algorithm-scripting-return-largest-numbers-in-arrays/583958/4 "2023-01-10T10:56:29Z")

</div>

We have blurred this solution (with `[spoiler][/spoiler]` tags) so that users who have not completed this challenge can read the discussion in this thread without giving away the solution.

---

<div class="post-metadata">

**Author:** ![hbar1st](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/hbar1st/32/372649_2.png) [@hbar1st](https://forum.freecodecamp.org/u/hbar1st)\
**Post date:** [January 10, 2023, 10:58am UTC](https://forum.freecodecamp.org/t/basic-algorithm-scripting-return-largest-numbers-in-arrays/583958/5 "2023-01-10T10:58:23Z")

</div>

Try doing this without the second loop.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [July 11, 2023, 10:58pm UTC](https://forum.freecodecamp.org/t/basic-algorithm-scripting-return-largest-numbers-in-arrays/583958/6 "2023-07-11T22:58:41Z")

</div>

Closed on July 11, 2023, 10:58pm UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
