Created
January 27, 2016 21:56
-
-
Save tmcw/0fa5d9deec799f0fbaa3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
function shallowEqual(objA, objB, tell) { | |
if (objA === objB) { | |
return true; | |
} | |
var keysA = Object.keys(objA); | |
var keysB = Object.keys(objB); | |
if (keysA.length !== keysB.length) { | |
return false; | |
} | |
// Test for A's keys different from B. | |
var hasOwn = Object.prototype.hasOwnProperty; | |
for (var i = 0; i < keysA.length; i++) { | |
if (!hasOwn.call(objB, keysA[i]) || objA[keysA[i]] !== objB[keysA[i]]) { | |
if (tell) { | |
return keysA[i]; | |
} | |
return false; | |
} | |
} | |
return true; | |
} | |
module.exports = shallowEqual; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment