Basic Algorithm Scripting - Reverse a String

So judging by this solution, you can just treat strings as if they are arrays? There is no conversion required it seems… Odd.

function reverseString(str) {
let reversedStr = “”;
for (let i = str.length - 1; i >= 0; i–) {
reversedStr += str[i];
}
return reversedStr;

return str;
}

reverseString(“hello”);

Okay that makes sense, thanks.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.