reduce 2
reduce 3
Améliorations :
const words = [1,2,2,1,5];
let { max, average } = words.reduce(function( {max, min, sum, nb}, x) {
min = Math.min(min,x);
max = Math.max(max,x);
sum = sum + x;
let average = sum/++nb;
return { min, max, nb, sum, average, nb }
},
{min : Number.MAX_VALUE,
max : Number.MIN_VALUE,
sum : 0,
average : 0,
nb : 0});