Created
June 22, 2020 06:38
-
-
Save kuboon/efb4d025333f0dea10b6667062e77a57 to your computer and use it in GitHub Desktop.
JSON compare
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
export function comp(x: any, y: any): boolean { | |
if (typeof x === 'object') { | |
const keys = Object.keys(x) | |
if (keys.length !== Object.keys(y).length) return false | |
return keys.every(k=>comp(x[k], y[k])) | |
} | |
return x === y | |
} | |
const a = {a:1,b:2,c:{a:1,b:3}} | |
const b: typeof a = {a:1,c:{a:1,b:3}, d:3} | |
console.log(comp(a, b)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment