Skip to content

Instantly share code, notes, and snippets.

@SeeThruHead
Created October 19, 2015 04:28
Show Gist options
  • Save SeeThruHead/89e094ec18c72b7ff9c8 to your computer and use it in GitHub Desktop.
Save SeeThruHead/89e094ec18c72b7ff9c8 to your computer and use it in GitHub Desktop.
Check for duplicate chars, if duplicated replace with ')' else '('
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