Created
October 31, 2022 22:59
-
-
Save Ivannnnn/a9ad70cba1b0ab1ad29baea446f4644e to your computer and use it in GitHub Desktop.
This file contains 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 = | |
(...options) => | |
(data) => { | |
const result = {}; | |
for (let option of options) { | |
if (option.constructor.name === "Array") { | |
option = option.reduce((acc, val) => ({ ...acc, [val]: val }), {}); | |
} | |
for (let key in option) { | |
result[key] = | |
typeof option[key] === "function" | |
? option[key](data) | |
: data[option[key]]; | |
} | |
} | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment