kstoyanov

01. Word Tracker js fundamentals

Jul 10th, 2020
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(args) {
  2.   const wordsOc = {};
  3.  
  4.   const searchWords = args.shift().split(' ');
  5.  
  6.   searchWords.forEach((searchWord) => {
  7.     const isFind = args.filter((word) => word.localeCompare(searchWord) === 0);
  8.     wordsOc[searchWord] = isFind.length;
  9.   });
  10.  
  11.   const sortedWords = Object.keys(wordsOc).sort((a, b) => wordsOc[b] - wordsOc[a]);
  12.  
  13.   sortedWords.forEach((word) => {
  14.     console.log(`${word.trimStart()} - ${wordsOc[word]}`);
  15.   });
  16. }
Add Comment
Please, Sign In to add comment