How to find the longest substring that consists of the same char?
问题 Now I try to solve task about finding length the longest substring that consists of the same char. For example, I have a string yyuuufhvksoooo , then I will get result 4 . I wrote this code, here it is: function longRepeat(line) { if (line.length > 0) { var count = 1; var max = 1; } for (let i = 0; i < line.length - 1; i++) { if (line[i] == line[i + 1]) { count++; if (count > max) max = count; } else { count = 1; } } return max; } It is work. But when I test this code with big string,