Created
September 25, 2016 23:15
-
-
Save Last-Order/8e489266b451c9539254c398342ce5cc to your computer and use it in GitHub Desktop.
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
"use strict" | |
var dict = {}; | |
var appendToDict = (char) => { | |
if (dict[char]) dict[char]++ | |
else dict[char] = 1; | |
} | |
var convert = (string) => { | |
string.toLowerCase().split('').map(appendToDict); | |
for (key of Object.keys(dict)) { | |
string = string.replace(new RegExp(key, 'ig'), dict[key] % 2 == 0 ? '\$' : '#'); | |
} | |
return string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment