Side note - you were just on the previous algorithm challenge. I wouldn’t jump right to the answers before figuring out how to do the algorithm challenges for yourself. This section is really where you start to learn how to become a programmer.
From my understanding, the first condition of for loop is the starting point, the second condition is the ending point, and the third condition is increment/decrement.
I understand that i-- indicates that the loop is decrementing by 1.
But how does i = str.length - 1; i >= 0; reverses the string?
It’s best to think of the clauses in a for loop as loop (index) initializtion; loop (index) test; index adjustment rather than as starting and ending points. Each clause can be arbitrarily complex (but you should keep them as simple as possible).
In fact, the code blocks
for(let i=0; i<some_limit; i++) {
// do stuff
}
and
let i=0;
while(i<some_limit) {
// do stuff
i++;
}
are functionally equivalent.
With that out of the way, to directly answer your confusion, the for loop in the posted solution doesn’t reverse a string. So what does it do? If you can answer that, you’ll be well on your way to understanding.