-2
I commented on Re-turn sum, on purpose, because I didn’t understand. If I remove Return sum, it returns the right average, I do not understand when it enters the if in the last position this return shows Nan. But why returns Nan?
const mediaNumeros = numeros.reduce((sum, element, index, array) => {
sum = sum + element;
if (index == array.length - 1) {
return Number((sum / array.length).toFixed(2));
}
// return sum;
}, 0)
Related: https://answall.com/q/480776/69296
– Luiz Felipe