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?
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.
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.
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.
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.
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 ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With