Skip to content

Instantly share code, notes, and snippets.

@bijeebuss
Created June 9, 2018 01:29
Show Gist options
  • Save bijeebuss/3b3bd53f069460c7d321d070486f8ed2 to your computer and use it in GitHub Desktop.
Save bijeebuss/3b3bd53f069460c7d321d070486f8ed2 to your computer and use it in GitHub Desktop.
function getLongestRepeating(input: string) {
const letters = input.split('');
let longestLetter = '';
let longestLength = 0;
for(let i = 0; i < letters.length; i++) {
const letter = letters[i];
let currentLength = 0;
for(let j = 0; j < letters.length; j++) {
const innerLetter = letters[j];
if(innerLetter === letter) {
currentLength += 1;
}
else {
currentLength = 0;
}
if(currentLength > longestLength) {
longestLetter = letter;
longestLength = currentLength;
}
}
}
return longestLength;
}
console.log(getLongestRepeating(''));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment