Skip to content

Instantly share code, notes, and snippets.

@prestigegodson
Created March 17, 2021 13:20
Show Gist options
  • Save prestigegodson/188e57483741e725dc947aca3be45129 to your computer and use it in GitHub Desktop.
Save prestigegodson/188e57483741e725dc947aca3be45129 to your computer and use it in GitHub Desktop.
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);
}
}
return undefined;
}
console.log(first_repeating_character("BACDEFGHIJBQWERUAAAA"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment