Function to test if two objects are equal
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
/** | |
* This function takes two objects and compares if they have the same | |
* keys and their keys have the same values assigned, so the objects are | |
* basically the same. | |
* @param {object} objA | |
* @param {object} objB | |
* @return {boolean} | |
*/ | |
const objectsEqual = (objA, objB) => { | |
const objAKeys = Object.keys(objA); | |
const objBKeys = Object.keys(objB); | |
const valueIsEqual = key => objB.hasOwnProperty(key) && objA[key] === objB[key]; | |
return ( | |
objAKeys.length === objBKeys.length | |
&& objAKeys.every(valueIsEqual) | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment