Skip to content

Instantly share code, notes, and snippets.

@Ivannnnn
Created October 31, 2022 22:59
Show Gist options
  • Save Ivannnnn/a9ad70cba1b0ab1ad29baea446f4644e to your computer and use it in GitHub Desktop.
Save Ivannnnn/a9ad70cba1b0ab1ad29baea446f4644e to your computer and use it in GitHub Desktop.
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