传入不固定参数求和,使用rest参数 reduce函数

function x(...list){
return list.reduce((sum,n)=>sum+n,0);
}

x(1,2,3);  // 6

x(); // 0

 

posted @ 2020-11-30 01:04  new一个小洛  阅读(61)  评论(0编辑  收藏  举报