Add the same tag twice and report the size.
Acceptance criteria
- 1.#out should show 2.
JavaScript Tutorial · JavaScript Map & Set
These 10 tasks go with the JavaScript Set chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “A Set stores unique values, automatically ignoring duplicates.” Read the chapter.
1.Ignore a duplicateexercise · easy · 10 min
Add the same tag twice and report the size.
Passes when: #out should show 2.
2.Remove duplicates from an arrayexercise · easy · 10 min · practice plan
Turn the array into unique values and join them.
Passes when: #out should show 1,2,3.
3.Check membershipexercise · easy · 10 min · practice plan
Report whether the colour is allowed.
Passes when: #out should show not allowed.
4.Show strict comparisonexercise · easy · 10 min · practice plan
Add the number one and the text one, then report the size.
Passes when: #out should show 2.
5.Loop over a Setexercise · medium · 10 min · practice plan
Collect the tags in order and join them.
Passes when: #out should show js,css,html.
6.Fix the Set never spreadbug fix · easy · 8 min
A Set is not an array, so it must be spread before joining.
Passes when: #out should show 1,2,3.
7.Fix length used instead of sizebug fix · easy · 8 min · practice plan
A Set counts with size, not length.
Passes when: #out should show 2.
8.Fix includes used on a Setbug fix · easy · 8 min · practice plan
A Set checks membership with has.
Passes when: #out should show not allowed.
9.Fix push used to addbug fix · easy · 8 min · practice plan
A Set is added to with add, not push.
Passes when: #out should show 2.
10.Fix the objects that did not deduplicatebug fix · easy · 8 min · practice plan
A Set compares objects by identity, so dedupe by a key instead.
Passes when: #out should show 1 unique.
Between them these tasks cover Set, Uniqueness and Deduplication.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.