Skip to content

Instantly share code, notes, and snippets.

@evandocarmo
Last active August 12, 2017 00:38
Show Gist options
  • Save evandocarmo/d30aa7d4f86d190f3bd19d12dca41339 to your computer and use it in GitHub Desktop.
Save evandocarmo/d30aa7d4f86d190f3bd19d12dca41339 to your computer and use it in GitHub Desktop.
Carthook Support Engineer Interview
//2. Write a short javascript function that displays the first non repeating character in a string.Example: If the string is "Alphabet", it would print out the letter "l"
function firstUnrepeatedLetter (word){
word = word.toLowerCase();
let hash = {};
for(let char of word){
if(!hash[char])
hash[char] = 1;
else
hash[char] += 1;
}
for(let key of Object.keys(hash)){
if(hash[key] === 1)
return key;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment