

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
Not enough gems
Cost: 6 gems
1: Sets
incomplete
2: Set Composition
incomplete
This lesson's interactive features are locked, please to keep using them
JavaScript added support for sets back in 2015 (still waiting on you to do the same, Golang...). A set is just a collection of unique values.
Sets are fantastic for de-duplication and checking if a value exists in a collection.
const set = new Set([1, 2, 3, 4, 5, 5, 5, 5]);
console.log(set);
// Set { 1, 2, 3, 4, 5 }
Notice that all duplicate instances of 5 were collapsed into one in the set. You can also add and delete values dynamically:
const set = new Set();
set.add("bertholdt");
set.add("reiner");
set.add("annie");
set.add("bertholdt");
console.log(set);
// Set { 'bertholdt', 'reiner', 'annie' }
set.delete("annie");
console.log(set);
// Set { 'bertholdt', 'reiner' }
Network conditions and retries are causing Textio to deliver duplicate email messages to our users. Complete the deduplicateEmails function. It takes an array of strings emails and returns a new array containing only unique messages.
The spread operator ... also works for sets!