Skip to content

Instantly share code, notes, and snippets.

@SergProduction
Created November 7, 2017 19:47
Show Gist options
  • Select an option

  • Save SergProduction/46387a7329b07267f362ef202ede6ec4 to your computer and use it in GitHub Desktop.

Select an option

Save SergProduction/46387a7329b07267f362ef202ede6ec4 to your computer and use it in GitHub Desktop.
function equalInterface(sample, eq) {
const type = t => Object.prototype.toString.call(t).slice(8,-1).toLocaleLowerCase()
debugger
let isEqual = true
if (type(sample) === 'object') {
Object.keys(sample).forEach(key => {
if (type(sample[key]) === 'object') {
const intoIsEqual = equalInterface(sample[key], eq[key])
console.log(sample[key], eq[key], intoIsEqual)
if (!intoIsEqual) {
isEqual = false
}
}
if (sample[key] !== type(eq[key])) {
isEqual = false
}
})
}
return isEqual
}
const d = {
x:1,
y:3,
l: {
e: 2
}
}
const result = equalInterface({
x: 'number',
y: 'number',
l: {
e: 'number',
}
}, d)
console.log(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment