Ejemplos de recursividad, Palindromas

Ejemplos de recursividad

Escribir una función que retorne true si el string enviado se lee igual que a la inversa.

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;
}

VPN

  • Ir a la oferta de NordVPN

Moda

Accesorios