Last active
October 7, 2016 12:12
-
-
Save Last-Order/591089071e4aa400c223efb5ae34f7cd 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 escapeRegExp = string => { | |
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); | |
} | |
var convert = string => { | |
string.toLowerCase().split('').map(appendToDict); | |
for (var key of Object.keys(dict)) { | |
string = string.replace(new RegExp(escapeRegExp(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