1let flattened = [[0, 1], [2, 3], [4, 5]].reduce(
2 function(accumulator, currentValue) {
3 return accumulator.concat(currentValue)
4 },
5 []
6)
7// flattened is [0, 1, 2, 3, 4, 5]
8
1//note idx and sourceArray are optional
2const sum = array.reduce((accumulator, element[, idx[, sourceArray]]) => {
3 //arbitrary example of why idx might be needed
4 return accumulator + idx * 2 + element
5}, 0);