Skip to main content

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

    Ignore a duplicate

    easy10 min

    Add the same tag twice and report the size.

  2. 2

    Remove duplicates from an array

    easy10 min

    Turn the array into unique values and join them.

  3. 3

    Check membership

    easy10 min

    Report whether the colour is allowed.

  4. 4

    Show strict comparison

    easy10 min

    Add the number one and the text one, then report the size.

  5. 5

    Loop over a Set

    medium10 min

    Collect the tags in order and join them.

Find the bug(5)

  1. 1

    Fix the Set never spread

    easy8 min

    A Set is not an array, so it must be spread before joining.

  2. 2

    Fix length used instead of size

    easy8 min

    A Set counts with size, not length.

  3. 3

    Fix includes used on a Set

    easy8 min

    A Set checks membership with has.

  4. 4

    Fix push used to add

    easy8 min

    A Set is added to with add, not push.

  5. 5

    Fix the objects that did not deduplicate

    easy8 min

    A 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