I am following James Moore's Functional programming for beginners with JavaScript course. However, I am currently having difficulties understanding the following code:
const reviews = [4.5, 4.0, 5.0, 2.0, 1.0, 5.0, 3.0, 4.0, 1.0, 5.0, 4.5, 3.0, 2.5, 2.0];
const countGroupedByReview = reviews.reduce(groupBy, {});
function groupBy (acc, review){
const count = acc[review] || 0;
return {...acc, [review]: count + 1}
}
While I understand the way in which the reduce method works, I am struggling to make sense of the code within the groupBy function block. I believe this has something to do with computed property names. I would be very grateful for any help.
Thanks.