Learning JavaScript and doing some questions. I am trying to reverse a given string and I don't know why my logic is wrong as running through the debugger it looks like it's doing the swapping as intended.
Any help is really appreciated, I know it's simple but that means I'm missing something important.
function reverse(s) {
let i = 0;
let j = s.length - 1;
while (i < j) {
let temp = s[j];
s[j] = s[i];
s[i] = temp;
i++;
j--;
}
return s;
}
console.log(reverse("hello"));