掘金日常学习2019-07-16

对数组求和
const numArr = [1,2,3,4,5,6,7,8,9,10]
方法一:高斯的 倒序相加法 (a0 +a(n))*n/2

let arr1 = arr => {
        return (arr[0]+arr[arr.length-1])*arr[arr.length-1]/2
}
arr1([1,2,3,4,5,6,7,8,9,10]);  //55

你可能感兴趣的:(掘金日常学习2019-07-16)