1
I have this code to remove the first and last spaces but it’s removing all the spaces present.
Follows:
const separador = ' ';
function filtro(separador, str) {
let resultado = '';
let stringNova = '';
for (let i = 0; i < str.length; i++) {
if (str[i] === separador) {
resultado += str[i];
} else {
stringNova += str[i];
}
}
return stringNova;
}
console.log(filtro(separador, (" X DSA ")));
Should return:
X DSA
and not XDSA
.
Someone could help me ?
Guys, I’m actually creating a trim method of my own, so I don’t want to use the trim method of the JS itself
+1 for several reasons
– Sam