Skip to content
Subhajit Sahu edited this page Jun 15, 2020 · 29 revisions

Gives values present in any iterable. 🏃 📼 📦 🌔 📒

Similar: union, intersection, difference, symmetricDifference.

iterable.union(x, y, [fc], [fm]);
// x:  an iterable
// y:  another iterable
// fc: compare function (a, b)
// fm: map function (v, i, x)

⏱️ Compare function => O(n²).

const iterable = require('extra-iterable');

var x = [1, 2, 3, 4];
var y = [3, 4, 5];
[...iterable.union(x, y)];
// [ 1, 2, 3, 4, 5 ]

var y = [-3, -4, -5];
[...iterable.union(x, y)];
// [
//    1,  2,  3, 4,
//   -3, -4, -5
// ]

[...iterable.union(x, y, (a, b) => Math.abs(a) - Math.abs(b))];
// [ 1, 2, 3, 4, -5 ]

[...iterable.union(x, y, null, v => Math.abs(v))];
// [ 1, 2, 3, 4, -5 ]

references

Clone this wiki locally