I have got an array with timecodes, it's look like this: ["5:43", "2:33", "3:45", "0:47", "5:21", "6:56", "3:46", "5:25", "3:14", "3:31", "5:59", "3:07", "11:29", "8:57", "5:49", "5:52", "5:50", "9:13", "11:51", "7:58", "4:40", "4:45", "6:46", "7:24", "7:12", "5:23", "3:34", "8:22", "5:17", "3:10", "4:43", "19:43", "0:47", "0:47", "3:14", "3:59", "2:43", "4:17", "6:56", "3:05", "2:06", "1:59", "1:49", "3:36", "7:10", "3:44", "3:44", "4:36", "3:16", "1:10", "6:10", "2:14", "3:44", "5:05", "6:03", "12:39", "1:56", "4:04"]
.
I need to sum seconds inside an array, by one reduce method.
Var timer gives me the right list of numbers, which I need to sum. For some reason, it doesn't want to sum it by itself. If I make the timer var an array and push things inside - they have no indexes, so I can't reduce them.
time.reduce((sum, cur) => {
const [mins, secs] = cur.split(':');
let timer;
timer = (parseFloat(mins * 60) + parseFloat(secs));
console.log(timer);
});
question from:
https://stackoverflow.com/questions/65879058/sum-timecodes-in-array-using-only-reduce