Skip to main content

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. 1

    Combine two sets

    easy10 min

    Build the union and join the values.

  2. 2

    Find what is in both

    easy10 min

    Build the intersection and join the values.

  3. 3

    Find what is only in the first

    easy10 min

    Build the difference and join the values.

  4. 4

    Find what is only in the second

    easy10 min

    Reverse the difference and join the values.

  5. 5

    Check for a subset

    medium10 min

    Report whether every value of the small set is in the big one.

Find the bug(5)

  1. 1

    Fix the union keeping duplicates

    easy8 min

    The combined array must go back through a Set.

  2. 2

    Fix the intersection inverted

    easy8 min

    The filter keeps what the other set does not have.

  3. 3

    Fix the difference taken the wrong way

    easy8 min

    Difference depends on which set comes first.

  4. 4

    Fix includes used inside the filter

    easy8 min

    A Set checks membership with has.

  5. 5

    Fix some used for a subset check

    easy8 min

    Every 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