Created
June 9, 2018 01:29
-
-
Save bijeebuss/3b3bd53f069460c7d321d070486f8ed2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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