Created
October 19, 2015 04:28
-
-
Save SeeThruHead/89e094ec18c72b7ff9c8 to your computer and use it in GitHub Desktop.
Check for duplicate chars, if duplicated replace with ')' else '('
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 check = (char, ind, word) => ~word.slice(0, ind).indexOf(char) | |
|| ~word.slice(ind + 1).indexOf(char) ? ')' : '('; | |
function duplicateEncode(word) { | |
return word | |
.toLowerCase() | |
.split('') | |
.map(check) | |
.join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment