UNPKG

ds-algo-study

Version:

Just experimenting with publishing a package

22 lines (15 loc) 649 B
/*********************************************************************** Write a function using fat arrow syntax, `arrowAvgValue(array)` that takes in an array of numbers and returns the average number. Assign the below function to a variable using the const keyword. Examples: arrowAvgValue([10, 20]); // => 15 arrowAvgValue([2, 3, 7]); // => 4 arrowAvgValue([100, 60, 64]); // => 74.66666666666667 ***********************************************************************/ const arrowAvgValue = array => { let sum = array.reduce((el, sum = 0) => (sum += el)); let avg = sum / array.length; return avg; }; module.exports = arrowAvgValue;