Last active
June 16, 2016 08:34
-
-
Save bogdanpetru/af10052671a0ab54993864bc28766ad3 to your computer and use it in GitHub Desktop.
Determines if two objects are equal based a list of keys
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
/** | |
* Determines if two objects are equal based on a list of keys | |
* | |
* object1, object2: Object | |
* keys: Array | |
*/ | |
function keysEqual(object1, object2, keys) { | |
for (let i = 0, len = keys.length; i < len; i++) { | |
const key = keys[i]; | |
// if one key is not euqal then the two objets are not equal | |
// based on the provided keys | |
if (object1[key] !== object2[key]) { | |
return false; | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment