JSFiddle - React, Tailwind, and code Playground
by Eric Howe
HTML
<script src="http://underscorejs.org/underscore-min.js"></script>
JavaScript
var input = [
{ name: 0, value: 'waffles' },
{ name: 0, value: 'pancakes' },
{ name: 0, value: 'french toast' },
{ name: 1, value: 'pancakes' }
];
function them_into_groups(m, h) {
m[h.name] || (m[h.name] = [ ]);
m[h.name].push(h.value);
return m;
}
function them_back_to_objects(v, k) {
return {
name: +k,
value: v
};
}
var output = _(input).chain()
.reduce(them_into_groups, { })
.map(them_back_to_objects)
.value();
console.log(output);