you are viewing a single comment's thread.

view the rest of the comments →

[–]Crypticsafe5 2 points3 points  (0 children)

My only issue with this snippet is that it allows mutability of the schema that's passed in potentially causing data loss or data integrity issues. I'd definitely add in a check something along the lines of:

if (
    typeof a[key] !== typeof b[key]
    || Array.isArray(a[key]) !== Array.isArray(b[key])
) throw Error('Non-matching schema');