This is a snippet of JavaScript. The reduce
function is being called to count a number of occurrences, and return the count to the variable total
. The reduce
function call can be generalized as reduce(array, someFunction, start){function body}
.
The specific instance of reduce
being used below is of the form reduce(array, (a,b) => a + b, 0)
. In the snippet below, how is the expression {count}
being used, and why is it wrapped in curly {}
brackets?. It seems to me it is neither a function body nor an object.
let total = scripts.reduce((n, {count}) => n + count, 0);
if (total == 0) return "No scripts found";