Skip to content

Instantly share code, notes, and snippets.

@mitrakmt
Created September 26, 2016 14:53
Show Gist options
  • Save mitrakmt/935f196a0a3086771523f541d8022ccb to your computer and use it in GitHub Desktop.
Save mitrakmt/935f196a0a3086771523f541d8022ccb to your computer and use it in GitHub Desktop.
Covering the common characters programming interview question in JavaScript.
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