Skip to content

Instantly share code, notes, and snippets.

@gonzazoid
Created March 12, 2017 13:07
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 gonzazoid/a5946ce550c8d1cd7049bad22495a315 to your computer and use it in GitHub Desktop.
Save gonzazoid/a5946ce550c8d1cd7049bad22495a315 to your computer and use it in GitHub Desktop.
const checkOff = function(target, pattern){
return Object.keys(pattern).every(key => {
const T = typeof(pattern[key]);
return (target.hasOwnProperty(key) &&
(pattern[key] === null ||
(T === typeof(target[key]) &&
(Array.isArray(pattern[key])
? Array.isArray(target[key])
: (T === 'object'
? checkOff(target[key], pattern[key])
: true
)
)
)
)
);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment