Created
December 3, 2019 18:13
-
-
Save hectorromo/e0de8f49d528078dc77d3986fb8b0bfd to your computer and use it in GitHub Desktop.
pick and reject
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
function reject(obj, keys) { | |
return Object.keys(obj) | |
.filter(k => !keys.includes(k)) | |
.map(k => Object.assign({}, {[k]: obj[k]})) | |
.reduce((res, o) => Object.assign(res, o), {}); | |
} | |
function pick(obj, keys) { | |
return keys.map(k => k in obj ? {[k]: obj[k]} : {}) | |
.reduce((res, o) => Object.assign(res, o), {}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment