I would like to take an array of arrays and concatenate the next item with the last array in the array.
var array = [
["thomas"],
["jane"],
["harry"],
]
array = processArray(array);
console.log(array);
[
["thomas"],
["thomas", "jane"],
["thomas", "jane", "harry"],
]
Whats a good way to do this? Before I dive into it I was wondering if there was a simple way using underscore.
var processArray = function(grouped){
var prev = false;
var map = _.map(grouped, function(value, key) {
if (prev) value.concat(grouped[prev]);
prev = key;
var temp = {};
temp[key] = value;
return temp;
});
return _.extend.apply(null, map);
}