Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
indiesquidge opened this issue May 18, 2017 · 0 comments
Assignees

Comments

@indiesquidge
Copy link
Owner

indiesquidge commented May 18, 2017

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 indiesquidge self-assigned this Jul 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant