DEV Community

Discussion on: Higher-order functions in Javascript

Collapse
 
jsonpoindexter profile image
Jason Poindexter • Edited

Excellent post. This helped a lot. I was wondering, what does the zero do here?:

let average = grades => (
    grades.reduce((acc, curr) => (
        acc + curr.grade
    ), 0) / grades.length
)
Enter fullscreen mode Exit fullscreen mode
Collapse
 
damcosset profile image
Damien Cosset

The reduce function takes an optional second parameter that indicates the initial value. If I wanted to start counting from 10,that second parameter would have been 10. Here, I wanted to start counting from 0.