Skip to content

p52 Defect in example code #29

@cuccagna

Description

@cuccagna

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions