DEV Community

Discussion on: 1 line of code: How to reverse a string

 
lexlohr profile image
Alex Lohr

My bad, typed that on the cellphone.

const reverseString = str => { let r = ''; for (let i = str.lenght; i >= 0;) r += str[--i]; return r }
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
frankwisniewski profile image
Frank Wisniewski

The function doesn't return anything...it seems to be an old turntable phone..;-)

Thread Thread
 
lexlohr profile image
Alex Lohr • Edited

I'll try it later when I have my PC.

Found the issue, but it is indeed slower.