Skip to content

Commit 53591a1

Browse files
authored
Merge pull request #96 from marcode24/2024-16-ts
✨ Add typescript solution challenge-16
2 parents a0ef4de + a108995 commit 53591a1

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* eslint-disable no-console */
2+
// Función para extraer todos los números de un texto
3+
function extractNumbers(text) {
4+
const numbers = text.match(/\d+/g);
5+
return numbers.map(Number) || [];
6+
}
7+
8+
// Función para validar un email
9+
function validateEmail(email) {
10+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
11+
return emailRegex.test(email);
12+
}
13+
14+
// Función para validar un número de teléfono
15+
function validatePhoneNumber(phoneNumber) {
16+
// eslint-disable-next-line max-len
17+
const phoneRegex = /^\+?\d{1,4}?[-.\s]?(\d{1,3}?[-.\s]?\d{1,4}[-.\s]?\d{1,4}[-.\s]?\d{1,9})$/;
18+
return phoneRegex.test(phoneNumber);
19+
}
20+
21+
// Función para validar una URL
22+
function validateURL(url) {
23+
const urlRegex = /^(https?:\/\/)?([\w-]+\.)+[\w-]+(\/[\w-]*)*\/?(\?.*)?(#.*)?$/i;
24+
return urlRegex.test(url);
25+
}
26+
27+
// Extracción de números
28+
const text = 'El precio es 1234, la cantidad es 5678, y el código es 90.';
29+
const numbers = extractNumbers(text);
30+
console.log('Números encontrados:', numbers); // ["1234", "5678", "90"]
31+
32+
// Validación de email
33+
const email = 'ejemplo@dominio.com';
34+
console.log('Email válido:', validateEmail(email)); // true
35+
36+
// Validación de número de teléfono
37+
const phoneNumber = '+123-456-7890';
38+
console.log('Número de teléfono válido:', validatePhoneNumber(phoneNumber)); // true
39+
40+
// Validación de URL
41+
const url = 'https://www.ejemplo.com';
42+
console.log('URL válida:', validateURL(url)); // true

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ npm run test 'year'/'folder-name'/solution.test.js
6565
| 13 | [Pruebas Unitarias](https://retosdeprogramacion.com/roadmap/) | 🟢 | [![JavaScript](https://img.shields.io/badge/-JavaScript-F7DF1E?style=flat&logo=javascript&logoColor=black)](./2024/13-pruebas-unitarias/index.js) |
6666
| 14 | [Fechas](https://retosdeprogramacion.com/roadmap/) | 🟢 | [![JavaScript](https://img.shields.io/badge/-JavaScript-F7DF1E?style=flat&logo=javascript&logoColor=black)](./2024/14-fechas/index.js) <br /> [![TypeScript](https://img.shields.io/badge/-TypeScript-3178C6?style=flat&logo=typescript&logoColor=white)](./2024/14-fechas/solution.ts) |
6767
| 15 | [Asincronía](https://retosdeprogramacion.com/roadmap/) | 🔴 | [![JavaScript](https://img.shields.io/badge/-JavaScript-F7DF1E?style=flat&logo=javascript&logoColor=black)](./2024/15-asincronia/index.js) |
68-
| 16 | [Expresiones Regulares](https://retosdeprogramacion.com/roadmap/) | 🟡 | [![JavaScript](https://img.shields.io/badge/-JavaScript-F7DF1E?style=flat&logo=javascript&logoColor=black)](./2024/16-expresiones-regulares/index.js) |
68+
| 16 | [Expresiones Regulares](https://retosdeprogramacion.com/roadmap/) | 🟡 | [![JavaScript](https://img.shields.io/badge/-JavaScript-F7DF1E?style=flat&logo=javascript&logoColor=black)](./2024/16-expresiones-regulares/index.js) <br /> [![TypeScript](https://img.shields.io/badge/-TypeScript-3178C6?style=flat&logo=typescript&logoColor=white)](./2024/16-expresiones-regulares/solution.ts) |
6969
| 17 | [Iteraciones](https://retosdeprogramacion.com/roadmap/) | 🟢 | [![JavaScript](https://img.shields.io/badge/-JavaScript-F7DF1E?style=flat&logo=javascript&logoColor=black)](./2024/17-iteraciones/index.js) |
7070
| 18 | [Conjuntos](https://retosdeprogramacion.com/roadmap/) | 🟢 | [![JavaScript](https://img.shields.io/badge/-JavaScript-F7DF1E?style=flat&logo=javascript&logoColor=black)](./2024/18-conjuntos/index.js) |
7171
| 19 | [Enumeraciones](https://retosdeprogramacion.com/roadmap/) | 🟡 | [![JavaScript](https://img.shields.io/badge/-JavaScript-F7DF1E?style=flat&logo=javascript&logoColor=black)](./2024/19-enumeraciones/index.js) |

0 commit comments

Comments
 (0)