String converter

by Mohan 2012-09-20 22:46:16





String converter
JavaScript 1.8
function CreateTranslator(translationTable) function(s) s.replace(new RegExp([k for (k in translationTable)].join('|'), 'g'), function(str) translationTable[str]);
exemple of use:
var translationTable = { a:1, bb:2, b:3, c:4 };
var MyTranslater = CreateTranslator( translationTable );
MyTranslater('aabbbc'); // returns: 11234




812
like
0
dislike
0
mail
flag

You must LOGIN to add comments