Last active
August 23, 2017 04:42
-
-
Save baetheus/006829ca6c417d846af03da08c733235 to your computer and use it in GitHub Desktop.
Scan and lodash
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
| /* | |
| This will turn your arrays into a keyed object like: | |
| { | |
| 1: <Obj 1>, | |
| 2: <Obj 2>, | |
| 3: <Obj 3> | |
| } | |
| Newest values will over-write old values. | |
| */ | |
| const keyedSource = source.scan((acc, arr) => _.assign(acc, _.keyby(arr, 'id')); | |
| /* | |
| This will take that keyed object and map it to an array like: | |
| [<Obj 1>, <Obj 2>, <Obj 3>] | |
| */ | |
| const backToArray = keyedSource.map(_.values); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment