Home > @wixc3/common > same
Deep comparison of two objects
Signature:
export declare function same<T>(a: T, b: T, unordered?: boolean): boolean;
Parameter | Type | Description |
---|---|---|
a | T | |
b | T | |
unordered | boolean | _(Optional)_ \[false\] Note: relevant only in array like iterables. objects, sets and maps are \*never checked for order\* of entries |
Returns:
boolean
items are “the same” if:
a === b (for anything other than iterables & POJO)
a and b are POJO with same entries (order ignored, same() used to compare values)
a and b are Maps with same entries (order ignored, same() used to compare keys & values)
a and b are Sets with same values (order ignored, same() used to compare values)
a and b are iterable (that are not Set or Map) with the same values, order checked if unordered=false (default)
same({a:1, b:2},{b:2, a:1}) // => true
same(new Map([['a',1],['b',2]]), new Map([['b',2],['a',1]])) // => true
same(new Map([[{a:1},{b:1}]]]), new Map([[{a:1},{b:1}]]])) // => true
same([0,1], [1,0]) // => false
same([0,1], [1,0], true) // => true