Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

flat One Level

Working With Arrayseasy

Course · Section 11: Working With Arrays · Lecture 170: flat and flatMap

Implement `flattenOne(arr)` flattening one level of nesting using `flat`.

Sample tests

Input: flattenOne([1,[2,3],[4]])
Output: [1,2,3,4]
Input: flattenOne([[1],[2]])
Output: [1,2]

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Deeper nesting needs flat(depth) or flat(Infinity).
Approach & explanation (try first)

flat with the default depth merges one level of nested arrays.

Loading...
⌘/Ctrl + Enter

Run your code to see results.