JavaScript Set — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Set 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
Ignore a duplicate
easy10 minAdd the same tag twice and report the size.
- 2
Remove duplicates from an array
easy10 minTurn the array into unique values and join them.
- 3
Check membership
easy10 minReport whether the colour is allowed.
- 4
Show strict comparison
easy10 minAdd the number one and the text one, then report the size.
- 5
Loop over a Set
medium10 minCollect the tags in order and join them.
Find the bug(5)
- 1
Fix the Set never spread
easy8 minA Set is not an array, so it must be spread before joining.
- 2
Fix length used instead of size
easy8 minA Set counts with size, not length.
- 3
Fix includes used on a Set
easy8 minA Set checks membership with has.
- 4
Fix push used to add
easy8 minA Set is added to with add, not push.
- 5
Fix the objects that did not deduplicate
easy8 minA Set compares objects by identity, so dedupe by a key instead.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace