Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Longest Block in String
- const input = ['abbb'];
- const print = this.print || console.log;
- const gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
- const strA = gets().split(''); // print(strA) // [ 'h', 'o', 'o', 'p', 'a' ]
- let arrN = [];
- let countMax = 1;
- let count = 1;
- if (strA.length >= 2) {
- for (let i = 0; i < strA.length - 1; i++) {
- if (strA[i] === strA[i + 1]) {
- count++;
- if (count > countMax) {
- countMax = count;
- arrN = [];
- for (let j = 0; j < countMax; j++) {
- arrN.push(strA[i]);
- }
- }
- } else {
- count = 1;
- }
- }
- }
- print(arrN.join(''));
Advertisement
Add Comment
Please, Sign In to add comment