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 ...

Get Learning JavaScript Data Structures and Algorithms - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.