Skip to content

difference

wolfram77 edited this page Mar 27, 2020 · 28 revisions

Gives values of an iterable not present in another.

Alternatives: compare, map.

iterable.difference(x, y, [fn]);
// x:  an iterable
// y:  another iterable
// fn: compare function (a, b)
const iterable = require('extra-iterable');

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

[...iterable.difference(x, [-2, -4])];
// [1, 2, 3, 4, 5]

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

references

Clone this wiki locally