-
Notifications
You must be signed in to change notification settings - Fork 5
compare
Subhajit Sahu edited this page May 3, 2023
·
18 revisions
Compare two arrays (lexicographically).
function compare(x, y, fc, fm)
// x: an array
// y: another array
// fc: compare function (a, b)
// fm: map function (v, i, x)
const xarray = require('extra-array');
var x = [1, 2];
var y = [1, 2, 3];
xarray.compare(x, y);
// → -1
var y = [1, 2];
xarray.compare(x, y);
// → 0
var y = [1, -2];
xarray.compare(x, y);
// → 1
xarray.compare(x, y, (a, b) => Math.abs(a) - Math.abs(b));
// → 0
xarray.compare(x, y, null, v => Math.abs(v));
// → 0