知识卡片

问题卡 · 6432

滚动平均需核对窗口端点

理解等级:中级

原例slice含起点不含终点,所以中间位置的[index-size,index+size)并非左右各size再含当前点的2size+1窗口。size=0还可能产生空窗口和除零。需先定义窗口、边缘裁剪与最少样本,再比较输出,不能只凭函数名认定常见窗口约定。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • · 查看原书依据

      end=index+size>list.length? list.length: index+size; win=list.slice(start,end);/*取平均值*/ return win.reduce(function(accumulator,current) { return accumulator+current; },0)/(end-star

    参考来源

    - 位置:《HTML 5应用开发实践指南》第2章《数组迭代操作》(spine358;extracted/OReilly精品图书系列共21册(《Javascript权威指南》、《机器学习:实用案例解析》、《编写可读代码的艺术》、《算法精解》等)/_epub-src/text/part0338.html;u020-ch02-027)。 - 结论依据:原文在“end=index+size”附近的定义、例子或代码支撑本卡核心说明:原例slice含起点不含终点,所以中间位置的[index-size,index+size)并非左右各size再含当前点的2size+1窗口。边界按已读前提解释;示例未执行。 - 原始内容:end=index+size>list.length? list.length: index+size; win=list.slice(start,end);/*取平均值*/ return win.reduce(function(accumulator,current) { return accumulator+current; },0)/(end-star