js finding average of an array using .reduce with example
Example 1: reduce average javascript
function average(nums) {
// nums.length is the important part
return nums.reduce((a, b) => (a + b)) / nums.length;
}
Example 2: javascript average of arguments
const average = (...args) => args.reduce((a, b) => a + b) / args.length;
// Example
average(1, 2, 3, 4); // 2.5