0
Leet Speak - Please Help me with this code
Hello coders, In this code standard letters are replaced by numerals or special characters. I've used javascript Object for this to store letters and their special characters. I'm stuck at the last part and get the error that says undefined. Could you help me! https://code.sololearn.com/WX1kpu9jW6u0
2 Answers
0
Because you're setting each character in the new string to something defined in your leetSpeak object, not every character will be accounted for considering that leetSpeak only defines 6 letters. To go around this, you can use this line of code which, while ugly and there are probably better ways of going about it, works well for this particular situation:
newWord += (Object.values(leetSpeak).indexOf(str[i]) > -1 ? leetSpeak[str[i]] : str[i]);