//累加时长方法
function calculateCumulativeSum(array, key) {
return array.reduce((accumulator, currentValue, currentIndex) => {
if (currentIndex === 0) {
accumulator[currentIndex] = currentValue[key];
} else {
accumulator[currentIndex] = accumulator[currentIndex - 1] + currentValue[key];
}
accumulator[currentIndex][key] = accumulator;
return accumulator;
}, []);
}
找某个数与数组中绝对差值最小的元素
//循环找出当前时间应该播放哪个视频
//与当前进度条最接近的 即将要播放的视频对象
let closestObject = data.reduce((prev, current) => {
const prevDiff = Math.abs(prev.StartFromZeroSpan - value);
const currentDiff = Math.abs(current.StartFromZeroSpan - value);
return prevDiff < currentDiff ? prev : current;
});