-
Notifications
You must be signed in to change notification settings - Fork 3
compare
Subhajit Sahu edited this page Dec 8, 2022
·
12 revisions
Compare two objects.
function compare(x, y, fc, fm)
// x: an object
// y: another object
// fc: compare function (a, b)
// fm: map function (v, k, x)
const object = require('extra-object');
var x = {a: 1, b: 2};
var y = {a: 1, b: 2, c: 3};
object.compare(x, y);
// → -1
var y = {a: 1, b: 2};
object.compare(x, y);
// → 0
var y = {a: 1, b: -2};
object.compare(x, y);
// → 1
object.compare(x, y, (a, b) => Math.abs(a) - Math.abs(b));
// → 0
object.compare(x, y, null, v => Math.abs(v));
// → 0