Last active
March 17, 2021 13:47
-
-
Save Aagbator/e4ca568e4c51e1ac3e39d7f93f75448f 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 first_repeating_character(ch) { | |
if(!ch){ | |
return null; | |
} | |
let charSet = new Set(ch) | |
for (var c of [...ch] ) { | |
if(charSet.has(c)){ | |
return c; | |
} | |
else { | |
charSet.add(c) | |
} | |
} | |
return 'None' | |
} | |
function first_repeating_character(characters) { | |
if (characters == undefined || characters.length == 0) { | |
return undefined; | |
} | |
let dict = {}; | |
for (i = 0; i < characters.length; i++) { | |
if (dict[characters.charAt(i)] == undefined) { | |
dict[characters.charAt(i)] = true; | |
} else { | |
return characters.charAt(i); | |
} | |
} | |
console.log(dict); | |
return undefined; | |
} | |
console.log(first_repeating_character("ACDEFGHIAJBQWERUAAAA")); | |
console.log(first_repeating_character('CDEFGHIJQWERUAAAA')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment