mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
740 B
34 lines
740 B
'use strict';
|
|
|
|
module.exports = function equal(a, b) {
|
|
if (a === b) return true;
|
|
|
|
var arrA = Array.isArray(a)
|
|
, arrB = Array.isArray(b)
|
|
, i;
|
|
|
|
if (arrA && arrB) {
|
|
if (a.length != b.length) return false;
|
|
for (i = 0; i < a.length; i++)
|
|
if (!equal(a[i], b[i])) return false;
|
|
return true;
|
|
}
|
|
|
|
if (arrA != arrB) return false;
|
|
|
|
if (a && b && typeof a === 'object' && typeof b === 'object') {
|
|
var keys = Object.keys(a);
|
|
|
|
if (keys.length !== Object.keys(b).length) return false;
|
|
|
|
for (i = 0; i < keys.length; i++)
|
|
if (b[keys[i]] === undefined) return false;
|
|
|
|
for (i = 0; i < keys.length; i++)
|
|
if(!equal(a[keys[i]], b[keys[i]])) return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
};
|
|
|