@extra-array/compare
v2.10.19
Published
Compares two arrays.
Downloads
381
Readme
Compares two arrays. :package: :smiley_cat: :running: :vhs: :moon: :scroll: :newspaper: :blue_book:
This is part of package extra-array.
array.compare(x, y, [fc], [fm]);
// x: an array
// y: another array
// fc: compare function (a, b)
// fm: map function (v, i, x)
// → x<y: -1, x=y: 0, x>y: 1
const array = require("extra-array");
var x = [1, 2];
var y = [1, 2, 3];
array.compare(x, y);
// -1
var y = [1, 2];
array.compare(x, y);
// 0
var y = [1, -2];
array.compare(x, y);
// 1
array.compare(x, y, (a, b) => Math.abs(a) - Math.abs(b));
// 0
array.compare(x, y, null, v => Math.abs(v));
// 0