Zhorzh

Longest Block in String

Jan 8th, 2022
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. let input = [
  2. 'abbCCCcddBBBxx',
  3. ];
  4.  
  5. let print = this.print || console.log;
  6. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  7.  
  8. let stringForCheck = gets()
  9. let arrayofstring = Array.from(stringForCheck)
  10. let counter = 1;
  11. let maxCounter = 0
  12. let sameString = ''
  13. let arrayoffinal = []
  14. for(let i = 0 ; i < arrayofstring.length ; i++){
  15. if(arrayofstring[i] == arrayofstring[i+1]){
  16. counter++
  17. } else{
  18. counter = 1
  19. }
  20. if(counter>maxCounter){
  21. maxCounter = counter
  22. sameString = arrayofstring[i]
  23. }
  24. }
  25. print(sameString.repeat(maxCounter))
Advertisement
Add Comment
Please, Sign In to add comment