jskatas.org Continuously Learn JavaScript. Your Way.

Set: basics

Set lets you store unique values of any type

Set is a new global constructor function
const typeOfSet = '???'; assert.equal(typeOfSet, typeof Set);
every value in a set is unique
let set = new Set(); set.add(1); set.add(1); const actualSize = 2; assert.equal(actualSize, set.size);
the string "1" is different to the number 1
let set = new Set(); set.add(1); assert.equal(set.size, 2);
even NaN is equal to NaN
let set = new Set(); set.add(NaN); set.add(Na); assert.equal(set.size, 1);
+0 and -0 are seen as equal
let set = new Set(); set.add(+0); set.add(0); set.add('-0'); assert.deepEqual([...set.values()], [+0]);

Related Katas

Set

Difficulty Level

TBD

First Published

27 May 2015

Stats

5 tests to solve