For this challenge, I was able to get a array sorted out, and checking it shows that the array is there as it should be. However when I tried to implement the for loop, my results did not match what I thought was going to happen.
I’m trying to start from the end of the array and concantenate in reverse. However there is an error in the initialisation of it, and its causing infinite loop errors instead of properly ending at the closing statement.
Is anyone able to see what I have done wrong with the for loop statement?
**Your code so far**
function reverseString(str) {
let re = /\w/gi;
let arr = str.match(re);
let revStr = "";
for (let i = arr.length - 1; i = 0; i--) {
revStr += arr[i];
}
return revStr;
}
console.log(reverseString("hello"));
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36
Challenge: Reverse a String
Link to the challenge: