Advertisement
c-karadjov

Untitled

Dec 23rd, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(arr) {
  2.     let i,
  3.         j,
  4.         number,
  5.         count = 1,
  6.         bestCount = 0;
  7.  
  8.     arr.splice(0, 1);
  9.  
  10.     for (i = 0; i < arr.length; i += 1) {
  11.         for (j = i; j < arr.length; j += 1) {
  12.             if (arr[i] === arr[j]) {
  13.                 count += 1;
  14.                 if (count > bestCount) {
  15.                     bestCount = count;
  16.                     number = +arr[i];
  17.                 }
  18.             } else {
  19.                 count = 1;
  20.             }
  21.         }
  22.     }
  23.     console.log(number + ' (' + bestCount + ' times)');
  24. }
  25. solve(['13', '4', '1', '1', '4', '2', '3', '4', '4', '1', '2', '4', '9', '3']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement