Created
September 26, 2016 14:53
-
-
Save mitrakmt/935f196a0a3086771523f541d8022ccb to your computer and use it in GitHub Desktop.
Covering the common characters programming interview question in JavaScript.
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
const commonCharacters = (string1, string2) => { | |
const result = {}; | |
string1.split('').forEach(letter => { | |
if(string2.indexOf(letter) >= 0 && letter !== ' ') { | |
result[letter] = letter; | |
} | |
}); | |
return Object.keys(result).join(''); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment