import { Comp } from "https://deno.land/x/rimbu@0.13.0/common/internal.ts";
const { objectComp } = Comp;
Returns a Comp instance for objects that orders the object keys according to the given keyComp
, and then compares the corresponding
values using the given valueComp
. Objects are then compared as follows:
starting with the smallest key of either object:
- if only one of the objects has the key, the object with the key is considered to be larger than the other
- if both objects have the key, the values are compared with
valueComp
. If the values are not equal, this result is returned.
if the objects have the same keys with the same values, they are considered equal
Examples
Example 1
Example 1
const c = Comp.objectComp();
console.log(c.compare({ a: 1 }, { a: 1 }))
// => 0
console.log(c.compare({ a: 1 }, { a: 2 }) < 0)
// => true
console.log(c.compare({ b: 5 }, { a: 2 }) < 0)
// => true
console.log(c.compare({ a: 1, b: 2 }, { b: 5 }) < 0)
// => true
console.log(c.compare({ a: 1, b: 2 }, { b: 2, a: 1 }))
// => 0