|
| 1 | +# Challenge Description and Solution |
| 2 | + |
| 3 | +## English Version |
| 4 | + |
| 5 | +### Challenge Description |
| 6 | +Create a function that determines if a string is a palindrome, meaning it reads the same forwards and backwards. |
| 7 | + |
| 8 | +### Code Explanation |
| 9 | +The `isPalindrome` function converts the string to lowercase and removes spaces for comparison. It then compares the string with its reverse to determine if it is a palindrome. |
| 10 | + |
| 11 | +### Relevant Code Snippet |
| 12 | + |
| 13 | +```javascript |
| 14 | +function isPalindrome(s) { |
| 15 | + const normalized = s.toLowerCase().replace(/\s+/g, ''); |
| 16 | + return normalized === normalized.split('').reverse().join(''); |
| 17 | +} |
| 18 | +``` |
| 19 | + |
| 20 | +### Example Usage |
| 21 | + |
| 22 | +```javascript |
| 23 | +const testStrings = ["radar", "hello", "level", "world"]; |
| 24 | +testStrings.forEach(str => { |
| 25 | + console.log(`'${str}' is palindrome: ${isPalindrome(str)}`); |
| 26 | +}); |
| 27 | +``` |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +## Versión en Español |
| 32 | + |
| 33 | +### Descripción del Reto |
| 34 | +Crea una función que determine si una cadena es un palíndromo, es decir, que se lee igual de izquierda a derecha y de derecha a izquierda. |
| 35 | + |
| 36 | +### Explicación del Código |
| 37 | +La función `isPalindrome` convierte la cadena a minúsculas y elimina espacios para hacer la comparación. Luego compara la cadena con su reverso para determinar si es un palíndromo. |
| 38 | + |
| 39 | +### Fragmento de Código Relevante |
| 40 | + |
| 41 | +```javascript |
| 42 | +function isPalindrome(s) { |
| 43 | + const normalized = s.toLowerCase().replace(/\s+/g, ''); |
| 44 | + return normalized === normalized.split('').reverse().join(''); |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +### Ejemplo de Uso |
| 49 | + |
| 50 | +```javascript |
| 51 | +const testStrings = ["radar", "hello", "level", "world"]; |
| 52 | +testStrings.forEach(str => { |
| 53 | + console.log(`'${str}' es palíndromo: ${isPalindrome(str)}`); |
| 54 | +}); |
0 commit comments