This function has to return reversed string. For example, “dog” -> “god”. It works correctly but I don’t understand the logic and I need explanation
function reverse (str) {
if (str.length <= 1) return str;
return reverse(str.slice(1)) + str[0]
}