用js实现函数f1,f返回每次调用拿书列表和之积,集中函数f可以不限次数调用,每次调用的参数个数不定。f(1,2)(3)(4,5,6) = (1+2)*3*(4+5+6) 返回和之积
4条回答 默认 最新
Tengmaoqing 2018-09-23 03:47关注javascript
// 约定不传参数时 获取乘积结果 const f1 = (...args) => { if (args.length === 0) { if (!f1.ands) { return 0; } return f1.ands.reduce((p, c) => p * c, 1); } !f1.ands && (f1.ands = []); f1.ands.push(args.reduce((p, c) => p + c, 0)); return f1; } console.log(f1(1,2)(2)(3,4)());解决 无用评论 打赏 举报