Last active
January 10, 2017 20:14
-
-
Save wallyuva/0059c66fbef10f438262c505acdf4389 to your computer and use it in GitHub Desktop.
Reduce sample
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 data = [ | |
| { | |
| column1: 1.0, | |
| column2: 2.0 | |
| }, | |
| { | |
| column1: 1.1, | |
| column2: 2.0 | |
| }, | |
| { | |
| column1: 1.1, | |
| column2: 2.1 | |
| }, | |
| ]; | |
| var grouped = data.reduce( function (prev, item) { | |
| if (!prev[item.column1]) { | |
| prev[item.column1] = { | |
| group: [item.column2] | |
| } | |
| } else { | |
| prev[item.column1].group.push(item.column2); | |
| } | |
| return prev; | |
| }, {} ); | |
| console.dir(grouped, { depth: null }); | |
| var array = Object.keys(grouped).map(function (key) { | |
| return { | |
| column1: key, | |
| group: grouped.group | |
| } | |
| }); | |
| console.dir(array, { depth: null}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment