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

Add Objects.clear #7

Closed
felippepuhle opened this issue Aug 21, 2017 · 3 comments
Closed

Add Objects.clear #7

felippepuhle opened this issue Aug 21, 2017 · 3 comments

Comments

@felippepuhle
Copy link
Contributor

Something like

export function clear(dirtyObject) {
  const cleanObject = {};

  Object.keys(dirtyObject).forEach(key => {
    const value = dirtyObject[key];
    if (value === null || value.length === 0) {
      return;
    }

    cleanObject[key] = value;
  });

  return cleanObject;
}
@sibelius
Copy link
Member

I would rather use .reduce

and return a new object instead of mutating

@felippepuhle
Copy link
Contributor Author

Nice, I think that it's even better! 😄

@fakenickels
Copy link

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

3 participants