Skip to content

difference

Subhajit Sahu edited this page May 19, 2020 · 27 revisions

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

array.difference(x, y, [fn]);
// x:  an array
// y:  another array
// fn: compare function (a, b)

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

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

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

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

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

array.difference(x, y, null, v => Math.abs(v));
// [ 1, 3, 5 ]

references

Clone this wiki locally