Skip to content

difference

wolfram77 edited this page Apr 13, 2020 · 27 revisions

Gives values of an array not present in another. 🏃 📼 📦 🌔

Alternatives: compare, map.

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

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

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

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

references

Clone this wiki locally