+ 2
how to toUpperCase ignoring spaces?
need to tell the JS,to change every even string(counting from 0) to upperCase...(i have done it).but now i need to tell JS to ignore all spaces (' ')....every time string[i] === ' ' ;=> for loop restart his count from 0.. https://code.sololearn.com/WQSj4XN20912/?ref=app
10 Antworten
+ 3
Check this code.
https://code.sololearn.com/WeR1un9abt8P/?ref=app
+ 2
Григорий Бондарев hi,
Have you considered first using split method on the string.
It will convert your string into an array of strings.
string=string.split(" ");
Then if you need it to be a string type, you can use join() to get rid of the "," .
and finally apply your for loop to get all the even indexed caracters passed to uppercase.
+ 1
Григорий Бондарев check my code again. now the output is that what you want.
Just replacing the value of x 0 to -1.it's easy check it again.
+ 1
77rtoip ,maybe but after I read again his question I realized he wanted to ignore them,not remove them,maybe he needs to keep the original form of the string,if so I guess your solution and the Maninder $ingh one are more appropriate.At least he have choice.
0
Maninder $ingh almost... i need to make every even string for every word to upperCase (counting from 0 for each word). 0-th string must be upper,then 2-nd,then 4th.... in your code it 1st upper,then 3rd,then 5th....
0
My proposition:
https://code.sololearn.com/W9HYb0ZED6vV/?ref=app
0
Григорий Бондарев indeed you can combine .split(" ").join("")
https://code.sololearn.com/WDebeMd2h0UU/?ref=app
0
The solution with split function is better, if you consider that you can have more than one space between words.
0
Anyway it's not so simple as it look at the first glance ;-)
- 1
hello