I'm trying to create a function which would add together all the values from an array of times.
const times = ["00:00:50", "00:03:20", "00:00:50"]
What I've got so far
function sumTime(t1, t2, array = []) {
const times = [3600, 60, 1],
sum = [t1, t2, ...array]
.map((s) => s.reduce((s, v, i) => s + times[i] * v, 0))
.reduce((a, b) => a + b, 0);
return times
.map((t) => [Math.floor(sum / t), (sum %= t)][0])
.map((v) => v.toString().padStart(2, 0));
}
sumTime(times)
But I'm getting a error Cannot read property 'reduce' of undefined
. Not sure where I'm going wrong?