const average = data=>data.map((item, idx, origin)=>Math.round(origin.slice(0,idx+1).reduce((a, b)=>a + b, 0) / (idx + 1))); 1.用map遍历求值
2.map中的第三个参数origin可以放回当前的值
3.reduce((a+b)=>a+b,0)当a为undefined,0参数赋值给a
2023-09-24 14:22:57
const average = data=>data.map((item, idx, origin)=>Math.round(origin.slice(0,idx+1).reduce((a, b)=>a + b, 0) / (idx + 1))); 1.用map遍历求值
2.map中的第三个参数origin可以放回当前的值
3.reduce((a+b)=>a+b,0)当a为undefined,0参数赋值给a