Skip to content

Commit

Permalink
[Refactor] Use object.entries to compare objects instead of for loops.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Dec 9, 2015
1 parent 8bbacb7 commit 2517c21
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
17 changes: 3 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var isRegex = require('is-regex');
var isString = require('is-string');
var isSymbol = require('is-symbol');
var isCallable = require('is-callable');
var entries = require('object.entries');

var symbolValue = typeof Symbol === 'function' ? Symbol.prototype.valueOf : null;

Expand Down Expand Up @@ -128,20 +129,8 @@ module.exports = function isEqual(value, other) {
if (typeof value !== typeof other) { return false; }
if (value.isPrototypeOf(other) || other.isPrototypeOf(value)) { return false; }
if (getPrototypeOf(value) !== getPrototypeOf(other)) { return false; }
var key;
for (key in value) {
if (has.call(value, key)) {
if (!has.call(other, key)) { return false; }
if (!isEqual(value[key], other[key])) { return false; }
}
}
for (key in other) {
if (has.call(other, key)) {
if (!has.call(value, key)) { return false; }
if (!isEqual(other[key], value[key])) { return false; }
}
}
return true;

return isEqual(entries(value), entries(other));
}

return false;
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"is-number-object": "^1.0.3",
"is-regex": "^1.0.3",
"is-string": "^1.0.4",
"is-symbol": "^1.0.1"
"is-symbol": "^1.0.1",
"object.entries": "^1.0.3"
},
"devDependencies": {
"tape": "^4.2.2",
Expand Down

0 comments on commit 2517c21

Please sign in to comment.