Reverses array string Recursive

Reverses array string Recursive

by Hilarius Doren

HTML

<p>
Write a function that reverses a string using a recursive function. Input of function using char[] or array of character
</p>

JavaScript

function reverse(a) {
    if (!a.length) return a;
     return reverse(a.slice(1)).concat(a[0]);
}

console.log(reverse(['h','e','l','l','o']));
// output ['o','l','l','e','h']