Created
February 17, 2017 09:46
-
-
Save madeinfree/d1d13dc4ea292caaa3cc71c9f827fb91 to your computer and use it in GitHub Desktop.
shallowEqual
This file contains hidden or 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
const hasOwn = Object.prototype.hasOwnProperty | |
export default function shallowEqual(a, b) { | |
if (a === b) return true | |
let countA = 0 | |
let countB = 0 | |
for (let key in a) { | |
if (hasOwn.call(a, key) && a[key] !== b[key]) return false | |
countA++ | |
} | |
for (let key in b) { | |
if (hasOwn.call(b, key)) countB++ | |
} | |
return countA === countB | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment