Skip to content Skip to sidebar Skip to footer

Leet Speak Translator Critical Bug

Yesterday I posted an question regarding my leet speak JavaScript app - Making a leet speak translator Today aging posting about that. I've improved the code and finally having a c

Solution 1:

Your approach by splitting words by a space is (as you already noticed) not working for punctuation. So a better way is to recognize words one by one with paying attention to punctuation.

This one uses the replace() function of the string type. It replaces any found match by its corresponding word from your dictionary. The regex pattern [^,\.\s]+ detects any combination of characters that are not commas, dots or white-spaces (spaces, tabs, newlines etc.).

functionchangeWords() {
    // change special words returnchangeLetters().replace(
        /[^,\.\s]+/g,
        function(m) {
            return words[m] ? words[m] : m;
        }
    );
}

Post a Comment for "Leet Speak Translator Critical Bug"