Last change
on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[6a3a178] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | // do not edit .js files directly - edit src/index.jst
|
---|
| 4 |
|
---|
| 5 |
|
---|
| 6 |
|
---|
| 7 | module.exports = function equal(a, b) {
|
---|
| 8 | if (a === b) return true;
|
---|
| 9 |
|
---|
| 10 | if (a && b && typeof a == 'object' && typeof b == 'object') {
|
---|
| 11 | if (a.constructor !== b.constructor) return false;
|
---|
| 12 |
|
---|
| 13 | var length, i, keys;
|
---|
| 14 | if (Array.isArray(a)) {
|
---|
| 15 | length = a.length;
|
---|
| 16 | if (length != b.length) return false;
|
---|
| 17 | for (i = length; i-- !== 0;)
|
---|
| 18 | if (!equal(a[i], b[i])) return false;
|
---|
| 19 | return true;
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 |
|
---|
| 23 |
|
---|
| 24 | if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
|
---|
| 25 | if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
|
---|
| 26 | if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
|
---|
| 27 |
|
---|
| 28 | keys = Object.keys(a);
|
---|
| 29 | length = keys.length;
|
---|
| 30 | if (length !== Object.keys(b).length) return false;
|
---|
| 31 |
|
---|
| 32 | for (i = length; i-- !== 0;)
|
---|
| 33 | if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
|
---|
| 34 |
|
---|
| 35 | for (i = length; i-- !== 0;) {
|
---|
| 36 | var key = keys[i];
|
---|
| 37 |
|
---|
| 38 | if (!equal(a[key], b[key])) return false;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | return true;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | // true if both NaN, false otherwise
|
---|
| 45 | return a!==a && b!==b;
|
---|
| 46 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.