README
set-operations
Javascript Set operations with ES6 Sets.
Installation
npm i set-operations
tests
npm run test
build
npm run build
modules
args
isSubset, isSuperSet: (arrA, arrB)
- arrA - Array
- arrB - Array
union, intersection, difference, symmetric difference: (arrA, arrB, returnAsArray)
- arrA - Array
- arrB - Array
- returnAsArray - boolean , default - false, if set true, returns the result as an array instead of a Set.
isSuperSet
Superset (A ⊇ B) : check if Arr A is superset of Arr B, i.e all elements of B are also elements of A.
import {isSuperSet} from "set-operations";
isSuperSet([1, 8, 3, 5], [3, 8]);
// true
isSuperSet([1, 8, 3, 5], [3, 9]);
// false
isSuperSet(['apple', 'orange', 'banana'], ['banana']);
// true
isSubSet
Subset (A ⊆ B) : check if Arr A is subset of Arr B, i.e all elements of A are also elements of B.
import {isSubSet} from "set-operations";
isSubSet([4, 5], [1, 9, 4, 8, 34, 43, 5]);
// true
isSubSet(["red", "blue"], ["violet", "indigo", "blue", "green", "yellow", "orange", "red"]);
// true
union
Union (A ∪ B): create a set that contains the elements of both arr A and arr B.
import {union} from "set-operations";
union(["rio", "delhi", "nairobi"], ["morocco", "algeria", "texas"]);
// Set { "rio", "delhi", "nairobi", "morocco", "algeria", "texas" }
intersection
Intersection (A ∩ B): create a set that contains those elements of Arr A that are also in Arr B.
import {intersection} from "set-operations";
intersection([67, 21, 52, 78, 32, 321, 98, 97], [342, 52, 63, 89, 21]);
// Set { 21, 52 }
difference
Difference (A \ B): create a set that contains those elements of Arr A that are not in Arr B.
import {difference} from "set-operations";
difference([43, 562, 52, 223, 652, 1], [43, 42, 524, 542, 100, 52]);
// Set { 562, 223, 652, 1 }
symmetric difference
Symmetric Difference (A ∆ B): create a set of all elements which are in Arr A or Arr B but not both.
import {symmetricDifference} from "set-operations";
symmetricDifference([0, 1, 2, 3, 4], [5, 6, 7, 8, 9]);
// Set { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
symmetricDifference(["sun", "rises", "in", "the", "east"], ["sun", "sets", "in", "the", "west"])
// Set { "rises", "east", "sets", "west" }
License
MIT