1 | ## just-compare
|
2 |
|
3 | Part of a [library](../../../../) of zero-dependency npm modules that do just do one thing.
|
4 | Guilt-free utilities for every occasion.
|
5 |
|
6 | [Try it now](http://anguscroll.com/just/just-compare)
|
7 |
|
8 | ```js
|
9 | import 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
|
15 | compare([1, [2, 3]], [1, [2, 3]]); // true
|
16 | compare([1, [2, 3], 4], [1, [2, 3]]); // false
|
17 | compare({a: 2, b: 3}, {a: 2, b: 3}); // true
|
18 | compare({a: 2, b: 3}, {b: 3, a: 2}); // true
|
19 | compare({a: 2, b: 3, c: 4}, {a: 2, b: 3}); // false
|
20 | compare({a: 2, b: 3}, {a: 2, b: 3, c: 4}); // false
|
21 | compare([1, [2, {a: 4}], 4], [1, [2, {a: 4}]]); // false
|
22 | compare([1, [2, {a: 4}], 4], [1, [2, {a: 4}], 4]); // true
|
23 | compare(NaN, NaN); // true
|
24 | ```
|