Sikau

Data structures · Day 4 · about 40 min

Project: Review analyser

Word frequencies, top-k and anagram groups with maps.

What are customers saying?

The café has thousands of reviews. Build the analysis functions with maps and sets so they stay fast as reviews pile up.

Clean words first

This project uses nothing but arrays, maps and sets, yet it handles thousands of reviews comfortably — a good reminder that the right basic structure beats clever code.

Every analysis starts with the same step: turn messy text into clean words. Lowercase everything so "Great" and "great" count together, and keep only letters so punctuation doesn't create fake words like "tea!". A regular expression with match does it in one line and returns an array you can count, group and sort.

function words(text) {
  return text.toLowerCase().match(/[a-z]+/g) ?? [];
}

console.log(words("Great momo, great TEA!"));

The rest of this lesson

  • Top-k and groupingexplain
  • Why maps keep it fastexplain
  • Step to techniquematch
  • Anagram keypredict
  • Analyse reviewschallenge
  • Badge quizquiz
  • Unit 1 complete!recap

Continue this lesson free — run real code in your browser

Continue with Google

See all 13 lessons of Data structures