Advertisement
zarkoto223

LongestBlockInString

Jan 9th, 2024 (edited)
637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let input = ['aaabbbccccCCCCC'];
  2. let print = this.print || console.log;
  3. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  4.  
  5. let arr = gets().split('');
  6.  
  7.  
  8. let tempCount = 1;
  9. let totCount = 1;
  10. let currentSymb = arr[0];
  11. let longest = currentSymb;
  12.  
  13. for (let i = 0; i <= arr.length; i++) {
  14.     if (arr[i] === arr[i - 1]) {
  15.         tempCount++;
  16.         currentSymb += arr[i];
  17.     } else {
  18.         if (tempCount > totCount) {
  19.             totCount = tempCount;
  20.             longest = currentSymb
  21.         } tempCount = 1;
  22.         currentSymb = arr[i];
  23.     }
  24. }
  25. console.log(longest)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement