ajv/lib/compile/equal.js

38 lines
877 B
JavaScript
Raw Normal View History

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
var arrA = Array.isArray(a)
2015-08-11 21:13:08 +03:00
, arrB = Array.isArray(b)
, i;
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;
}
if (arrA != arrB) return false;
if (a && b && typeof a === 'object' && typeof b === 'object') {
var keysSet = {};
2015-06-02 02:14:38 +03:00
var keys = Object.keys(a);
var keys2 = Object.keys(b);
if (keys.length !== keys2.length) return false;
for (i = 0; i < keys.length; i++) {
keysSet[keys[i]] = 1;
}
for (i = 0; i < keys2.length; i++) {
keysSet[keys2[i]] = 1;
}
keys = Object.keys(keysSet);
2015-08-11 21:13:08 +03:00
for (i = 0; i < keys.length; i++)
2015-06-02 02:14:38 +03:00
if (!equal(a[keys[i]], b[keys[i]])) return false;
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
};