DEV Community

打coding的奥特曼
打coding的奥特曼

Posted on

求和

//将传入的参数转为数组
const turnArray = (...rest)=> [].slice.apply(rest);
//利用reduce对数组求和
const add = arr => arr.reduce((pre,cur)=>pre+cur);
console.log(add(turnArray(1,2,3,4,5,6)));
Enter fullscreen mode Exit fullscreen mode

Top comments (0)