Skip to content

Instantly share code, notes, and snippets.

@Last-Order
Last active October 7, 2016 12:12
Show Gist options
  • Save Last-Order/591089071e4aa400c223efb5ae34f7cd to your computer and use it in GitHub Desktop.
Save Last-Order/591089071e4aa400c223efb5ae34f7cd to your computer and use it in GitHub Desktop.
"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