Skip to content

Instantly share code, notes, and snippets.

@Aagbator
Last active March 17, 2021 13:47
Show Gist options
  • Save Aagbator/e4ca568e4c51e1ac3e39d7f93f75448f to your computer and use it in GitHub Desktop.
Save Aagbator/e4ca568e4c51e1ac3e39d7f93f75448f to your computer and use it in GitHub Desktop.
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