Examples
Write reverseString so that the following cases hold.
- Input
reverseString("hello")Output"olleh" - Input
reverseString("")Output"" - Input
reverseString("a")Output"a"
1 more hidden test cases - 4 in total will be graded.
Answer
text
function reverseString(str) {
return str.split("").reverse().join("");
}
reverseString("hello"); // "olleh"
Alternative: loop from the last character to the first, accumulating into a new string.
