Skip to content

Instantly share code, notes, and snippets.

@leafiy
Created May 18, 2018 18:54
Show Gist options
  • Save leafiy/728955e1930199bc9214914a86363e39 to your computer and use it in GitHub Desktop.
Save leafiy/728955e1930199bc9214914a86363e39 to your computer and use it in GitHub Desktop.
pick
const pick = (obj, arr) =>
arr.reduce((acc, curr) => (curr in obj && (acc[curr] = obj[curr]), acc), {});
// pick({ 'a': 1, 'b': '2', 'c': 3 }, ['a', 'c']) -> { 'a': 1, 'c': 3 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment