compare - nodef/extra-object GitHub Wiki

Compare two objects.

Similar: compare, isEqual.

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

References