【发布时间】:2018-12-04 06:13:56
【问题描述】:
我一直试图弄清楚如何在 reduce 方法中将 count 定义为 0,然后在函数中使用。有没有人可以逐步描述这段代码的工作原理?谢谢!
let ranges = [[125184, 125259], [125264, 125274], [125278, 125280]];
console.log(
ranges.reduce((count, [from, to]) => {
return count + (to - from);
}, 0)
);
【问题讨论】:
标签: javascript arrays reduce