Last active
August 29, 2015 14:06
-
-
Save pixelhijack/69d6c0536f99186e25b5 to your computer and use it in GitHub Desktop.
String converter translationtable
This file contains hidden or 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
/* | |
https://code.google.com/p/jslibs/wiki/JavascriptTips | |
*/ | |
function CreateTranslator(translationTable) function(s) s.replace(new RegExp([k for (k in translationTable)].join('|'), 'g'), function(str) translationTable[str]); | |
// usage: | |
var translationTable = { a:1, bb:2, b:3, c:4 }; | |
var MyTranslater = CreateTranslator( translationTable ); | |
MyTranslater('aabbbc'); // returns: 11234 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment