I am pretty new to javascript and I have an issue with flattening several arrays into one complete array using the reduce and concat function.
var array = [ [1, 3], [6, 6], [3, 3] ];
var finishedArray = function(array) {
var reducedArray = {};
var completeArray = {};
for (var i = 0; i < array.length; i++) {
reducedArray[i] = array[i].reduce(function (a, b) {
return a + b;
});
completeArray = reducedArray[i].concat(reducedArray[i + 1]);
}
return completeArray;
}
console.log(finishedArray(array));`
The error I get is : completeArray = reducedArray[i].concat(reducedArray[i + 1])
;
TypeError: undefined is not a function
Why is that???