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'.

Example: 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"
}

Tags:

Misc Example