In this article, we will explore the features of Sets and also look into a few examples where Sets can make our life easier.
A Set is a collection of elements that maintain insertion order, and only allows unique elements. If you insert five1’s in a row, only one will be inserted. When inserting, it will compare elements using
=== to determine if they should be inserted.
We need to be conscious of this fact because objects which are the exact same but have different references will in fact be inserted since they are being compared by reference.
How can we create a set? The simplest way is by using the Set constructor.
const mySet = new Set();
Who else loves to write side-effects-free functions? I think we, as programmers, all do. Today, in this story, I will walk you through the basic principles of functional programming that will make your coding life easier.