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

17th Sep 2019, 9:12 PM
Jojo
Jojo - avatar
2 Réponses
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]);
17th Sep 2019, 9:49 PM
Faisal
Faisal - avatar
17th Sep 2019, 11:00 PM
Aymane Boukrouh
Aymane Boukrouh - avatar