DEV Community

loading...
Cover image for #7DaysJS: Reverse a String

#7DaysJS: Reverse a String

lautarolobo profile image Lautaro Lobo Originally published at lautarolobo.xyz on ・1 min read

Welcome to day 4 of 7 Days of JavaScript!

Today we will see how to reverse a string. It’s probably the most asked question ever on technical interviews.

So the statement is quite simple, although the problem has an unexpected complexity when you face it for the first time: write a function that takes a string and returns the string reversed.

Here’s an example:

reverseString('Japan')
...
'napaJ'

Give it a try.

You can see the solutions I made here.

Discussion (2)

pic
Editor guide
Collapse
bharath_bheemireddy profile image
Bharath_Bheemireddy

const reverseString = str => str.split('').reverse().join('');
Collapse
lautarolobo profile image
Lautaro Lobo Author

That's I think the best way to do it!