O'Reilly logo

Learning JavaScript Data Structures and Algorithms - Second Edition by Loiane Groner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a set

The current implementation of JavaScript is based on ECMAScript 5.1 (supported by modern browsers) published on June 2011. It contains the Array class implementation that we covered in earlier chapters. ECMAScript 6 also contains an implementation of the Set class that you will learn how to use later on in this chapter. The class we will implement in this chapter is based on the Set implementation of ECMAScript 6.

This is the skeleton of our Set class:

function Set() { 
  let items = {}; 
} 

A very important detail here is that we are using an object to represent our set ( items ) instead of an array. However, we could also use an array to do this implementation. Let's use an object to implement things a little bit differently and discuss ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required