Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a library for a Set data type in Javascript?

Tags:

Since Javascript doesn't have a built in set datatype has anyone come across a decent library for sets and set operations like union, intersection, etc?

like image 210
Jason Christa Avatar asked Feb 26 '10 15:02

Jason Christa


People also ask

Do sets exist in JavaScript?

A JavaScript Set is a collection of unique values. Each value can only occur once in a Set. A Set can hold any value of any data type.

Is there a standard library for JavaScript?

stdlib (/ˈstændərd lɪb/ "standard lib") is a standard library for JavaScript and Node. js, with an emphasis on numerical and scientific computing applications.

What is Set data structure in JavaScript?

A Set data structure allows to add data to a container, a collection of objects or primitive types (strings, numbers or booleans), and you can think of it as a Map where values are used as map keys, with the map value always being a boolean true.

Is Set ordered in JavaScript?

A set is not an ordered abstract data structure. A Set however always has the same iteration order - element insertion order [1], so when you iterate it (by an iterating method, by calling Symbol. iterator , or by a for.. of loop) you can always expect that. You can always convert the set to an array and sort that.


1 Answers

Have a look at JS.Set.

The JS.Set class can be used to model collections of unique objects. A set makes sure that there are no duplicates among its members, and it allows you to use custom equality methods for comparison as well as JavaScript’s === operator.

It contains methods like union, intersection, merge, etc ...

like image 81
Sagi Avatar answered Sep 19 '22 18:09

Sagi