javascript-challenges
javascript-challenges copied to clipboard
Write me a function that will remove all undefined and null values from a JS object
Given this JS object
const george = {
name: 'George Costanza',
age: 37,
skills: undefined,
vocation: null
}
Write me a function that will return a new object (no mutation) with any null or undefined values excluded.
const newGeorge = removeNil(obj)
console.log(newGeorge) // { name: 'George Costanza', age: 37 }
Add in the ability for me to include source objects, similar to the ES6 Object.assign
method.
const art = removeNil(obj, { name: 'Art Vandelay', age: null, vocation: 'architect' })
console.log(art) // { name: 'Art Vandelay', vocation: 'architect' }