ErolKZ

Untitled

Nov 5th, 2021
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. function solve (arr) {
  2.  
  3. let words = arr.shift().split(' ');
  4.  
  5. let obj = {};
  6.  
  7. let arr2 = [];
  8.  
  9.  
  10. arr.forEach(el => words.includes(el) ? obj[el] = (obj[el] || 0) + 1 : false);
  11.  
  12. // console.log(obj);
  13.  
  14. let sortedArr = Object.entries(obj).sort((a, b) => b[1] - a[1]);
  15.  
  16. // console.log(sortedArr);
  17.  
  18.  
  19. for (let [key, value] of sortedArr) {
  20.  
  21. console.log(`${key} - ${value}`);
  22.  
  23. }
  24.  
  25.  
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment