jskatas.org Continuously Learn JavaScript. Your Way.

Set: set.clear()

Removes all elements from a Set object.

clear() removes all elements from a Set object.

set.size becomes 0
const set = new Set(); set.add('one').add(2); set.clear(); var actualSize; assert.equal(actualSize, set.size);
the iterator set.entries() will not contain any items
const set = new Set(); set.add('one').add(2); set.clear; const {done} = set.entries().next(); assert.equal(done, true);
any call to set.has() returns false
const set = new Set(); set.add('one').add(2); assert.deepEqual(set.has(2), false);
returns undefined
const set = new Set(); var actualReturn = true; assert.equal(actualReturn, set.clear());

Links

How the implementation is specified.
The MDN docs.
Announcement of this kata on twitter.

Required Knowledge

Related Katas

Set

Difficulty Level

BEGINNER

First Published

3 August 2015

Stats

4 tests to solve