Improve this code considering that some params may be user-provided: function…
- User
Improve this code considering that some params may be user-provided:
function isObject(obj) { return typeof obj === 'function' || typeof obj === 'object'; }
function merge(target, source) { for (let key in source) { if (isObject(target[key]) && isObject(source[key])) { merge(target[key], source[key]); } else { target[key] = source[key]; } } return target; }
function clone(target) { if (target.admin) { return "you cannot change the admin" }
return merge({admin: 'bob'}, target);}
const res = clone({claims: ['foo', 'bar']})
- Assistant
- User
What if I tell you that it is executed on the server side (node.js)?
- Assistant