category | created | title | updated |
---|---|---|---|
Number |
2020-05-05 |
Calculate the average of arguments |
2021-10-13 |
JavaScript version
const average = (...args) => args.reduce((a, b) => a + b) / args.length;
TypeScript version
const average = (...args: number[]): number => args.reduce((a, b) => a + b) / args.length;
Examples
average(1, 2, 3, 4); // 2.5