-
Notifications
You must be signed in to change notification settings - Fork 5
unique
Subhajit Sahu edited this page May 19, 2020
·
25 revisions
Removes duplicate values. 🏃 📼 📦 🌔
array.unique(x, [fn]);
// x: an array
// fn: compare function (a, b)
⏱️ Compare function => O(n²).
const array = require('extra-array');
var x = [1, 2, 3, 4, 2, 3];
array.unique(x);
// [ 1, 2, 3, 4 ]
var x = [1, 2, 3, 4, -2, -3];
array.unique(x, (a, b) => Math.abs(a) - Math.abs(b));
// [ 1, 2, 3, 4 ]
array.unique(x, null, v => Math.abs(v));
// [ 1, 2, 3, 4 ]