[Home] >  Number >  Calculate the average of arguments

Calculate the average of arguments

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