compare - nodef/extra-lists GitHub Wiki

Compare two lists.

Similar: compare, isEqual.

function compare(x, y, fc, fm)
// x:  lists
// y:  another lists
// fc: compare function (a, b)
// fm: map function (v, k, x)
const xlists = require('extra-lists');

var x = ['a', 'b'], [1, 2](/nodef/extra-lists/wiki/'a',-'b'],-[1,-2);
var y = ['a', 'b', 'c'], [1, 2, 3](/nodef/extra-lists/wiki/'a',-'b',-'c'],-[1,-2,-3);
xlists.compare(x, y);
// → -1

var y = ['a', 'b'], [1, 2](/nodef/extra-lists/wiki/'a',-'b'],-[1,-2);
xlists.compare(x, y);
// → 0

var y = ['a', 'b'], [1, -2](/nodef/extra-lists/wiki/'a',-'b'],-[1,--2);
xlists.compare(x, y);
// → 1

xlists.compare(x, y, (a, b) => Math.abs(a) - Math.abs(b));
// → 0

xlists.compare(x, y, null, v => Math.abs(v));
// → 0

References