Advertisement
AreWe

Words Tracker

Jul 13th, 2020
961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. wordsTracker = (arr = []) => {
  2.     return Object.entries(
  3.         arr.reduce(
  4.             (words, word) => (words[word] !== undefined ? Object.assign(words, { [word]: words[word] + 1 }) : words),
  5.             arr
  6.                 .shift()
  7.                 .split(' ')
  8.                 .reduce((initial, word) => Object.assign(initial, { [word]: 0 }), {}),
  9.         ),
  10.     )
  11.         .sort((a, b) => b[1] - a[1])
  12.         .map(([word, count]) => `${word} - ${count}`)
  13.         .join('\n');
  14. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement