JavaScript Array flat — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Array flat lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Flatten one level
easy10 minFlatten a nested array and join the result with commas.
- 2
Flatten two levels
easy10 minFlatten an array nested two deep and show the length.
- 3
Flatten completely
easy10 minUse Infinity to flatten however deep the nesting goes.
- 4
Split into words
easy10 minUse flatMap to split each sentence into words and join with commas.
- 5
Merge groups of names
medium10 minFlatten an array of groups and show the total number of people.
Find the bug(5)
- 1
Fix the default depth
easy8 minOne level is not enough for an array nested two deep.
- 2
Fix map used instead of flatMap
easy8 minmap leaves each result nested inside its own array.
- 3
Fix the result of flat being ignored
easy8 minflat returns a new array; it does not change the original.
- 4
Fix the fixed depth on unknown nesting
easy8 minThe nesting is deeper than the depth given.
- 5
Fix concat used on nested groups
easy8 minThe groups need flattening into one list of people.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace