Skip to main content

reverse

Write a recursive function called reverse which accepts a string and returns a new string in reverse.

Solution:

// reverse('awesome') // 'emosewa'
// reverse('rithmschool') // 'loohcsmhtir'

const reverse = (str) => {
if (str.length <= 1) return str;
// gb
return reverse(str.slice(1)) + str[0];
};