Created
October 12, 2018 15:54
-
-
Save petermenocal/1a32a75688aefd763695668d8f324fd1 to your computer and use it in GitHub Desktop.
group by key and sum a value
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
| var prjMgrValues = [ | |
| {"proj_mgr":"Jack ProjManager","submitted_dollars":12000}, | |
| {"proj_mgr":"Jack ProjManager","submitted_dollars":750000}, | |
| {"proj_mgr":"Joe ProjManager","submitted_dollars":45000} | |
| ]; | |
| var output = | |
| _(prjMgrValues) | |
| .groupBy('proj_mgr') | |
| .map((objs, key) => ({ | |
| 'proj_mgr': key, | |
| 'submitted_dollars': _.sumBy(objs, 'submitted_dollars') })) | |
| .value(); | |
| console.log(output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment