Name Frequency Count
Given a list of names, return an object mapping each name to the number of times it appears.
countNames(["Amy", "Bob", "Amy"]) -> { Amy: 2, Bob: 1 }
countNames([]) -> {}Names are case-sensitive: "amy" and "Amy" are different names.
Hints
Hint 1
One pass with a map from name to count; (counts[name] ?? 0) + 1 handles the first sighting.
Topics
Asked at
Sign in to use the assistant — ask what the problem means, get a hint when you're stuck, or have your current work reviewed. Conversations save to your account.