I know there are many other ways to reverse a string in JS
but I wrote this and it is not working and I want to understand why. Mine only has two extra parameters so I can tell it to reverse from here to there.
function strRev(str, startRev, endRev) {
while (startRev < endRev) {
let temp = str[startRev];
str[startRev] = str[endRev];
str[endRev] = temp;
startRev += 1;
endRev -= 1;
}
return str;
}
And usage:
let str = "STACK";
strRev(str, 0, str.length -1 );
But what I get as result is the same original string. I don't understand why.
It works when I trace it on paper.