2015-06-02 01:43:46 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
module.exports = function equal(a, b) {
|
|
|
|
if (a === b) return true;
|
2015-06-02 02:14:38 +03:00
|
|
|
|
2015-06-10 23:51:14 +03:00
|
|
|
var arrA = Array.isArray(a)
|
2015-08-11 21:13:08 +03:00
|
|
|
, arrB = Array.isArray(b)
|
|
|
|
, i;
|
2015-06-10 23:51:14 +03:00
|
|
|
|
|
|
|
if (arrA && arrB) {
|
2015-06-02 02:14:38 +03:00
|
|
|
if (a.length != b.length) return false;
|
2015-08-11 21:13:08 +03:00
|
|
|
for (i = 0; i < a.length; i++)
|
2015-06-02 02:14:38 +03:00
|
|
|
if (!equal(a[i], b[i])) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-10 23:51:14 +03:00
|
|
|
if (arrA != arrB) return false;
|
|
|
|
|
2015-06-14 01:41:33 +03:00
|
|
|
if (a && b && typeof a === 'object' && typeof b === 'object') {
|
2015-06-02 02:14:38 +03:00
|
|
|
var keys = Object.keys(a);
|
2015-09-07 01:45:10 +03:00
|
|
|
|
2015-09-07 11:58:33 +03:00
|
|
|
if (keys.length !== Object.keys(b).length) return false;
|
2015-09-07 01:45:10 +03:00
|
|
|
|
2015-09-07 11:58:33 +03:00
|
|
|
for (i = 0; i < keys.length; i++)
|
|
|
|
if (b[keys[i]] === undefined) return false;
|
2015-09-07 01:45:10 +03:00
|
|
|
|
2015-08-11 21:13:08 +03:00
|
|
|
for (i = 0; i < keys.length; i++)
|
2015-09-07 11:58:33 +03:00
|
|
|
if(!equal(a[keys[i]], b[keys[i]])) return false;
|
|
|
|
|
2015-06-02 02:14:38 +03:00
|
|
|
return true;
|
2015-06-02 01:43:46 +03:00
|
|
|
}
|
2015-06-02 02:14:38 +03:00
|
|
|
|
|
|
|
return false;
|
2015-08-11 21:13:08 +03:00
|
|
|
};
|