Advertisement
bebo231312312321

Untitled

Mar 7th, 2023
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function wordOccurrences(input) {
  2.     let words = {}
  3.     input.forEach(element => {
  4.         if (!words[element]) words[element] = 0
  5.         words[element]++
  6.     });
  7.     Object.entries(words).sort((a, b) => b[1] - a[1]).map(word =>
  8.         console.log(`${word[0]} -> ${word[1]} times`))
  9. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement