Answers for "Write a function reverse that reverses the order of the characters in a string. The function should be recursive. Example: reverse('live') should return 'evil'."

0

Write a function reverse that reverses the order of the characters in a string. The function should be recursive. Example: reverse('live') should return 'evil'.

function reverse(str) { // "bayrak"

    let splitStr = str.split('');  // ["b", "a", "y", "r", "a", "k"]
    let reverseArr = splitStr.reverse(); // ["k", "a", "r", "y", "a", "b"]
    let joinArr = reverseArr.join(''); // "karyab"
    return joinArr; // "karyab"
}
Posted by: Guest on January-01-2021

Code answers related to "Write a function reverse that reverses the order of the characters in a string. The function should be recursive. Example: reverse('live') should return 'evil'."

Browse Popular Code Answers by Language