UNPKG

902 BMarkdownView Raw
1## just-compare
2
3Part of a [library](../../../../) of zero-dependency npm modules that do just do one thing.
4Guilt-free utilities for every occasion.
5
6[Try it now](http://anguscroll.com/just/just-compare)
7
8```js
9import compare from 'just-compare';
10
11// primitives: value1 === value2
12// functions: value1.toString == value2.toString
13// arrays: if length, sequence and values of properties are identical
14// objects: if length, names and values of properties are identical
15compare([1, [2, 3]], [1, [2, 3]]); // true
16compare([1, [2, 3], 4], [1, [2, 3]]); // false
17compare({a: 2, b: 3}, {a: 2, b: 3}); // true
18compare({a: 2, b: 3}, {b: 3, a: 2}); // true
19compare({a: 2, b: 3, c: 4}, {a: 2, b: 3}); // false
20compare({a: 2, b: 3}, {a: 2, b: 3, c: 4}); // false
21compare([1, [2, {a: 4}], 4], [1, [2, {a: 4}]]); // false
22compare([1, [2, {a: 4}], 4], [1, [2, {a: 4}], 4]); // true
23compare(NaN, NaN); // true
24```