JavaScript Set Operations — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Set Operations 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
Combine two sets
easy10 minBuild the union and join the values.
- 2
Find what is in both
easy10 minBuild the intersection and join the values.
- 3
Find what is only in the first
easy10 minBuild the difference and join the values.
- 4
Find what is only in the second
easy10 minReverse the difference and join the values.
- 5
Check for a subset
medium10 minReport whether every value of the small set is in the big one.
Find the bug(5)
- 1
Fix the union keeping duplicates
easy8 minThe combined array must go back through a Set.
- 2
Fix the intersection inverted
easy8 minThe filter keeps what the other set does not have.
- 3
Fix the difference taken the wrong way
easy8 minDifference depends on which set comes first.
- 4
Fix includes used inside the filter
easy8 minA Set checks membership with has.
- 5
Fix some used for a subset check
easy8 minEvery value must be present, not just one.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace