DEV Community


Discussion on: Higher-order functions in Javascript

jsonpoindexter profile image
Jason Poindexter

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
damcosset profile image
Damien Cosset Author

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.