DEV Community

loading...
Cover image for Day 5 of JavaScriptmas - Reverse String Solution

Day 5 of JavaScriptmas - Reverse String Solution

Sekti
Keep moving forward. Learn well not learn fast.
・1 min read

Day 5 is Reverse string. The classic problem to reverse string.

For instance string 'Hello' reversed into 'olleH'.
Since a string can be split into array, we can reverse the arrangement of array with reverse and concat the array with join to reverse it back into single string.

There is JavaScript solution

function reverseAString(str) {
    return str.split('').reverse().join('');
}
Enter fullscreen mode Exit fullscreen mode

Discussion (0)