Skip to main content

sum

sum 计算数组的和

🍱 参数

  1. array - numbers

🔥 返回值

number - 平均值

🚀 示例

import { sum } from 'atools-js';

sum([1, 2, 3, 4, 5]); // 15

💡 源码

source code
/atools/_calc/sum.ts
export const sum = (numbers: number[]): number => {
return numbers.reduce((acc, curr) => acc + curr, 0);
};