Workshop › Text detective › Step 9 of 13

The most common word

What we are doing

The detective's finding: the word used most. We turn the map into a list, sort it by count and take the first.

```js
const top = [...counts].sort((a, b) => b[1] - a[1])[0]

(top ? '\nMost common: ' + top[0] + ' (' + top[1] + ')' : '')
```

What it means

Your turn

  1. After the loop, write the top line.
  2. Add the Most common part to the end of the report, as shown.

Skills: Arrays and objects, Functions

All steps

  1. Read the text
  2. Count the characters
  3. Update as you type
  4. Split into words
  5. The extra-space trap
  6. An empty box has no words
  7. Count each word
  8. Drop the punctuation
  9. The most common word
  10. Shift a letter
  11. Encode a whole text
  12. The secret line
  13. Build it yourself: crack the code