Created
April 24, 2018 00:39
-
-
Save juniorbird/66e6f1afd652c05b086c21f47a345397 to your computer and use it in GitHub Desktop.
Get First Repeating Character Example
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 getFirstRepeatingCharacter(someString) { | |
let len = someString.length; | |
let cache = {}; | |
for (let i = 0; i < len; i++) { | |
let currentLetter = someString.charAt(i); | |
if (cache[currentLetter]) return someString.charAt(i); | |
cache[currentLetter] = true; | |
} | |
// no result | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment