Created
February 5, 2022 19:21
-
-
Save alalfakawma/7313eca08ab7a2508ece5e9254521c0a 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
/* | |
* Check keys of objects | |
* return false if atleast 1 key does not match | |
* return true if all keys are the same | |
* | |
* @param key Array<string> | string | |
* @param obj1 { [key: string]: string } | |
* @param obj2 { [key: string]: string } | |
* @return boolean | |
*/ | |
function objectCompare<T>(key: Array<string> | string, obj1: { [key: string]: T }, obj2: { [key: string]: T }): boolean { | |
if (Array.isArray(key)) { | |
for (let i = 0; i < key.length; i++) { | |
if (obj1[key[i]] !== obj2[key[i]]) return false; | |
} | |
} else { | |
if (obj1[key] !== obj2[key]) return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment