# [solved] Problem FreeCodeCamp challenge

[solved] Problem FreeCodeCamp challenge
0

#1

Hi,

I’m trying to solve a challenge problem, this one : https://www.freecodecamp.org/challenges/return-largest-numbers-in-arrays

I used this logic :

``````function largestOfFour(arr) {
// You can do this!
return arr.filter(a => {
return a.sort((b, c) => c-b)[0];
})
.reduce(function (flat, toFlatten) {
return flat.concat(toFlatten);
}, []);
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
``````

For me, it should do the job, return what the sentence want, but it’s not the case, can someone tell me where is my mistake please ?

Thank you !

#2

Here is the solution

Spoiler
``````function largestOfFour(arr) {
// You can do this!
return arr.map(a => {
return a.sort((b, c) => c-b)[0];
})
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
``````

#3

@Mughees605 Please don’t post solutions in threads as it can spoil the learning experience for others.

Notice that the OP marked this as solved already, and they didn’t ask for a solution, just a hint about why it was broken.

I’ve also edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (`</>`) will also add backticks around text.