Making a leet speak translator

前端 未结 2 1795
孤独总比滥情好
孤独总比滥情好 2021-01-22 12:41

This works as what I want:

var elite = document.getElementById(\"elite\"),
  leet = document.getElementById(\"leet\"),
  alphabets = {
    a: \"4\",
    b: \"8\"         


        
2条回答
  •  终归单人心
    2021-01-22 13:24

    You would have to keep track of the replaced words in your text, so their individual letters won't get replaced by changeLetters(). This is needlessly complicated. You'll be better off running your changeLetters() algorithm over the values in your "words" object ("cool", "dude", ...). That way, you can keep the string literals sane (non-leet), but you can keep using the code you are using right now. (Make sure you store the "words" in the global scope and only convert your "words" object once.)

提交回复
热议问题