馃敟 EJEMPLOS DE RECURSIVIDAD, FUNCI脫N RECURSIVA VERDADERA

Ejemplos de recursividad

Escribir una funci贸n recursiva que acepte un arreglo y una funci贸n callback. La funci贸n retorna true si un valor en el arreglo returna true cuando sea enviado a la funci贸n callback. De otra forma que retorne false.

function esPalindroma(str) {
    if (str.length === 1) {
        return true;
    }

    if (str.length === 2) {
        return str[0] === str[str.length - 1];
    }

    if (str[0] === str[str.length - 1]) {
        return esPalindroma(str.slice(1, str.length - 1));
    }

    return false;
}