Guest User

Untitled

a guest
Jun 10th, 2021
76
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let input = ["13",
  2. '4',
  3. '1',
  4. '1',
  5. '4',
  6. '2',
  7. '3',
  8. '4',
  9. '4',
  10. '1',
  11. '2',
  12. '4',
  13. '9',
  14. '3'];
  15.  
  16. let gets =this.gets ||(  (arr, index) => () =>    arr[index++])(input, 0);
  17. let print = this.print || console.log;
  18.  
  19. let n = +gets();
  20. let hash = new Map();
  21.  
  22. for (var i = 0; i < n; i++) {
  23.     let num = +gets();
  24.   if (hash.has(num)) {
  25.     hash.set(num, hash.get(num) + 1);
  26.   } else {
  27.     hash.set(num, 1);
  28.   }
  29. }
  30.  
  31. let repeatedTimes = 0;
  32. let repeatingNumber = -1;
  33. hash.forEach((value, key) => {
  34.   if (repeatedTimes < value) {
  35.     repeatingNumber = key;
  36.     repeatedTimes = value;
  37.   }
  38. });
  39.  
  40. print(`${repeatingNumber} (${repeatedTimes} times)`);
RAW Paste Data