Basic Algorithm Scripting - Return Largest Numbers in Arrays

Sorry, a lazy JS beginner coder here. Could this solution fail any test, even those not included in the algo checks?

function largestOfFour(arr) {
  return (arr.length === 1) ? [Math.max(...arr[0])] : arr.map(innerArr => Math.max(...innerArr))
}

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

console.log(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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36

Challenge: Basic Algorithm Scripting - Return Largest Numbers in Arrays

Link to the challenge:

Could you clarify what you mean by “any test”?

I meant that, was I just lucky it passed all the tests for that exercise or the code is robust to work in any case.

We have blurred this solution so that users who have not completed this challenge can read the discussion in this thread without giving away the solution.

1 Like

i think the problem set is simple and there is no chance your code will fail some other unforeseen input. (well unless you get an empty array? but maybe that won’t be a problem)

1 Like

Thanks. Tried now and it returned an empty array as I expected it.

1 Like

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