Brainlag
  1. Library
  2. Challenges
  3. Web

Count the hashtags

Given a feed of posts with hashtags, count how often each tag is used, the way a trending list or a tag cloud does.

WebWarm-up15 min

Write countTags(posts). Each post is an object with a user and an array of tags. Return an object that maps each tag to how many times it was used across all the posts. Tags are counted in lower case, so "Gaming" and "gaming" are the same tag.

JavaScript
countTags([
  { user: "zara_x", tags: ["gaming", "speedrun"] },
  { user: "kofi99", tags: ["Gaming", "lofi"] },
]);
// { gaming: 2, speedrun: 1, lofi: 1 }

Checks

  1. Count every tag
  2. Any capitals count as the same tag
exercise_1.js to run
function countTags(posts) {
}

Code editor. Press Control or Command plus Enter to run the code. Tab indents; to move focus out of the editor, press Escape and then Tab.