Created
June 19, 2019 16:03
-
-
Save schulace/0929986b659e3fbda90cd29c620b44cb to your computer and use it in GitHub Desktop.
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 retain = (obj, keys) => { | |
| const keepStr = keys.join(', '); | |
| const evalStr = `(() => {const {${keepStr}} = obj;return {${keepStr}};})()` | |
| return eval(evalStr); | |
| } | |
| const obj = {'k1': 'v1', 'k2': 'v2'}; | |
| const newObj = retain(obj, ['k2']); | |
| console.log(newObj); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unfortunately, this is faster than
However, it is slower than just modifying acc in the reduce