Skip to content

Commit 807c79a

Browse files
committed
feat(js): add solution and documentation for easy challenge 6 - Palindrome checker
1 parent 0c3c101 commit 807c79a

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Challenge: Create a function that determines if a string is a palindrome, meaning it reads the same forwards and backwards.
2+
3+
function isPalindrome(s) {
4+
const normalized = s.toLowerCase().replace(/\s+/g, '');
5+
return normalized === normalized.split('').reverse().join('');
6+
}
7+
8+
// Example usage
9+
const testStrings = ["radar", "hello", "level", "world"];
10+
testStrings.forEach(str => {
11+
console.log(`'${str}' is palindrome: ${isPalindrome(str)}`);
12+
});

0 commit comments

Comments
 (0)