function sumPrices(...numbers){
return numbers.reduce(function(total,value){
return total + (Number.isNaN(Number(val)) ? 0 : Number(val));
}, 0);
}
The book say "To ensure the function produce a useful sum of its parameter values, however they are received......
sumPrices(100,200,true)
return 301 because Number(true) is 1
and there are other edge cases (as Infinity for example)
function sumPrices(...numbers){
return numbers.reduce(function(total,value){
return total + (Number.isNaN(Number(val)) ? 0 : Number(val));
}, 0);
}
The book say "To ensure the function produce a useful sum of its parameter values, however they are received......
sumPrices(100,200,true)
return 301 because Number(true) is 1
and there are other edge cases (as Infinity for example)