Created
December 4, 2018 17:00
-
-
Save luan0ap/727b809fdf668a598e17d659f141c979 to your computer and use it in GitHub Desktop.
pick a properties from object, by an array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const pick = (obj = {}) => (props = []) => { | |
| var picked = {} | |
| props.forEach((prop) => picked[prop] = obj[prop]) | |
| return picked | |
| } | |
| const lunch = { | |
| sandwich: 'turkey', | |
| drink: 'water', | |
| chips: 'salt and vinegar', | |
| desert: true | |
| } | |
| pick(lunch)(['drink', 'chips']) // { drink: 'water', chips: 'salt and vinegar' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment