Last active
August 12, 2017 00:38
-
-
Save evandocarmo/d30aa7d4f86d190f3bd19d12dca41339 to your computer and use it in GitHub Desktop.
Carthook Support Engineer Interview
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
//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