I have created my own algorithm to achieve the same outcome as this function:
var string= string.split(' ').join('');
For example, if I input the String: Hello how are you
, it should become Hellohowareyou
My approach avoids using .replace
, regex
, or .split
However, upon testing, my algorithm does not seem to alter the original String:
var x = prompt("Enter String");
for (var i=0; i<=x.length;i++) {
if (x[i] == " ") {
x[i] = "";
}
}
alert(x);