A set is a collection of unique values.

Usage no npm install needed!

<script type="module">
  import extraSetMin from 'https://cdn.skypack.dev/extra-set.min';


A set is a collection of unique values.
:package: NPM, :smiley_cat: GitHub, :running: RunKit, :vhs: Asciinema, :moon: Minified, :scroll: Files, :newspaper: JSDoc, :blue_book: Wiki.

Methods look like:

  • concat(): doesn't modify the map itself (pure).
  • concat$(): modifies the map itself (update).

Methods as separate packages:

Stability: Experimental.

This is browserified, minified version of extra-set.
It is exported as global variable set.
CDN: unpkg, jsDelivr.

const set = require("extra-set");
// import * as set from "extra-set";
// import * as set from "https://unpkg.com/extra-set@2.1.60/index.mjs"; (deno)

var x = new Set([1, 2, 3, 4, 5]);
var y = new Set([2, 4]);
set.difference(x, y);
// Set(3) { 1, 3, 5 }

var x = new Set([1, 2, 3]);
var y = new Set([3, 4]);
set.isDisjoint(x, y);
// false

var x = new Set([1, 2, 3, 4]);
var y = new Set([3, 4, 5, 6]);
set.symmetricDifference(x, y);
// Set(4) { 1, 2, 5, 6 }

var x = new Set([1, 2, 3]);
// [
//   Set(0) {},
//   Set(1) { 1 },
//   Set(1) { 2 },
//   Set(2) { 1, 2 },
//   Set(1) { 3 },
//   Set(2) { 1, 3 },
//   Set(2) { 2, 3 },
//   Set(3) { 1, 2, 3 }
// ]


Method Action
is Checks if value is set.
add Adds value to set.
remove Deletes a value.
size Gets size of set.
head Gets first value.
take Keeps first n values only.
shift Removes first value.
from Creates a set from values.
concat Appends values from sets.
flat Flattens nested set to given depth.
chunk Breaks set into chunks of given size.
filterAt Gets set with given values.
map Updates values based on map function.
filter Keeps values which pass a test.
reduce Reduces values to a single value.
range Finds smallest and largest entries.
count Counts values which satisfy a test.
partition Segregates values by test result.
cartesianProduct Lists cartesian product of sets.
some Checks if any value satisfies a test.
union Gives values present in any set.
intersection Gives values present in both sets.
difference Gives values of set not present in others.
symmetricDifference Gives values not present in both sets.
isDisjoint Checks if sets have no common values.
value Picks an arbitrary value.
entry Picks an arbitrary entry.
subset Picks an arbitrary subset.
isEmpty Checks if set is empty.
isEqual Checks if two sets are equal.
compare Compares two sets.
find Finds a value passing s test.
scanWhile Finds first value not passing a test.