DEV Community

Discussion on: JavaScript30: Day 4 - Solve Real Life challenges using Array Methods

Collapse
 
pentacular profile image
pentacular • Edited

I think this has a typo

 if (!obj.item) { //checks if the item is new

and should be generally obj[item].

But it might be a bit nicer like this:

const histogram = (map, key) => map.set(key, (map.get(key) || 0) + 1);

data.reduce(histogram, new Map())
Collapse
 
akdeberg profile image
Anik Khan • Edited

Hey many many thanks for the suggestion.😊 I hope many would find this helpful 💗