Q. Write a function which calculates the average of the numbers in a given list.
Note: Empty arrays should return 0.
//#my solution
function find_average(array) {
// your code here
if (array.length == 0) return 0;
let sum = array.reduce((a, b) => a + b);
return sum / array.length;
}
//#other solution
var find_average = (array) => {
return array.length === 0 ? 0 : array.reduce((acc, ind)=> acc + ind, 0)/array.length
}