JSFiddle - React, Tailwind, and code Playground
by jfriend00
JavaScript
"use strict";
//-------------------------------------------
// Implementation of a Set in javascript
//
// Supports any element type that can uniquely be identified
// with its string conversion (e.g. toString() operator).
// This includes strings, numbers, dates, etc...
// It does not include objects or arrays though
// one could implement a toString() operator
// on an object that would uniquely identify
// the object.
//
// Uses a javascript object to hold the Set
//
// s.add(key) // adds a key to the Set (if it doesn't already exist)
// s.add(key1, key2, key3) // adds multiple keys
// s.add([key1, key2, key3]) // adds multiple keys
// s.add(otherSet) // adds another Set to this Set
// s.add(arrayLikeObject) // adds anything that a subclass returns true on _isPseudoArray()
// s.remove(key) // removes a key from the Set
// s.remove(["a", "b"]); // removes all keys in the passed in array
// s.remove("a", "b", ["first", "second"]); // removes all keys specified
// s.has(key) // returns true/false if key exists in the Set
// s.hasAll(args) // returns true if s has all the keys in args
// s.equals(otherSet) // returns true if s has exactly the same keys in it as otherSet
// s.isEmpty() // returns true/false for whether Set is empty
// s.keys() // returns an array of keys in the Set
// s.clear() // clears all data from the Set
// s.union(t) // return new Set that is union of both s and t
// s.intersection(t) // return new Set that has keys in both s and t
// s.difference(t) // return new Set that has keys in s, but not in t
// s.isSubset(t) // returns boolean whether every element in s is in t
// s.isSuperset(t) // returns boolean whether every element of t is in s
//...