Dark Mode
Enable Console
reverseString(str)
/*
Takes a string as input and returns it with the characters reversed
*/
reverseString('world');
// "dlrow"
reverseString('JavaScript');
// "tpircSavaJ"
Solution by - Need4Swede
function reverseString(str){
// Splits the string into an array of characters
str = str.split("")
// Reverses the order of the array
str = str.reverse()
// Joins the array back into a string
str = str.join("")
// Returns the string
return str
}
Alternatively, you can write it like this...
function reverseString(str){
return str.split("").reverse().join("");
}
Try it yourself - Codewars Source