javascript-challenges icon indicating copy to clipboard operation
javascript-challenges copied to clipboard

Write me a function that will remove all undefined and null values from a JS object

Open indiesquidge opened this issue 7 years ago • 0 comments

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' }

indiesquidge avatar May 18 '17 17:05 indiesquidge