traverse a string char by char javascript
Posted
by
mikeandike
on Stack Overflow
See other posts from Stack Overflow
or by mikeandike
Published on 2014-08-25T16:09:29Z
Indexed on
2014/08/25
16:20 UTC
Read the original article
Hit count: 114
JavaScript
|charat
function SimpleSymbols(str) {
var letter =['a','b','c','d','e','f','g','h','i','j',
'k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
var newstr = "";
for (var i = 0; i<str.length; i++){
if (str.charAt(i).toLowerCase() in letter){
newstr += "M";
}
else{
newstr += "X";
}
}
return newstr;
}
If str is "Argument goes here" it returns XXXXXXXXX. WHy doesn't it return MMMMMMMMMM?
© Stack Overflow or respective owner