Skip to content

Instantly share code, notes, and snippets.

@kuboon
Created June 22, 2020 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuboon/efb4d025333f0dea10b6667062e77a57 to your computer and use it in GitHub Desktop.
Save kuboon/efb4d025333f0dea10b6667062e77a57 to your computer and use it in GitHub Desktop.
JSON compare
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