Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ec2a992

Browse files
Merge pull request #13 from marcode24/2021
✨ add challenge-20 solution
2 parents 8c29618 + 072141d commit ec2a992

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Reto 20: Una carta de pangramas que
2+
3+
## Problema
4+
5+
En la clase de español del pueblo de Laponia han creado un reto a la hora de escribir la carta a Papa Noél 🎅: la carta ✉️ tiene que contener todas las letras del alfabeto.
6+
7+
Desde el taller de Santa 🎅 se han enterado y quieren escribir **una función** que les diga si realmente la cadena de texto que les llega tiene, efectivamente, todas las letras del abecedario español 🔎.
8+
9+
Hay que tener en cuenta las letras en mayúscula y que las letras con acento y diéresis se consideran iguales. Por ejemplo la á y la ä cuenta como una a.
10+
11+
Vamos a ver unos ejemplos de frases:
12+
13+
```js
14+
pangram('Extraño pan de col y kiwi se quemó bajo fugaz vaho') // true
15+
pangram('Jovencillo emponzoñado y con walkman: ¡qué figurota exhibes!') // true
16+
17+
pangram('Esto es una frase larga pero no tiene todas las letras del abecedario') // false
18+
pangram('De la a a la z, nos faltan letras') // false
19+
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function pangram(str) {
2+
const cleanedStr = str
3+
.toLowerCase()
4+
.replace(/[áä]/g, 'a')
5+
.replace(/[éë]/g, 'e')
6+
.replace(/[íï]/g, 'i')
7+
.replace(/[óö]/g, 'o')
8+
.replace(/[úü]/g, 'u');
9+
10+
const uniqueLetters = new Set(cleanedStr);
11+
const allLetters = new Set('abcdefghijklmnñopqrstuvwxyz');
12+
13+
return [...allLetters].every((letter) => uniqueLetters.has(letter));
14+
}
15+
16+
module.exports = pangram;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const pangram = require('./index');
2+
3+
describe('20 => Una carta de pangramas que', () => {
4+
const testCases = [
5+
{
6+
input: 'Extraño pan de col y kiwi se quemó bajo fugaz vaho',
7+
output: true,
8+
},
9+
{
10+
input: 'Jovencillo emponzoñado y con walkman: ¡qué figurota exhibes!',
11+
output: true,
12+
},
13+
{
14+
input: 'Esto es una frase larga pero no tiene todas las letras del abecedario',
15+
output: false,
16+
},
17+
{
18+
input: 'De la a a la z, nos faltan letras',
19+
output: false,
20+
},
21+
];
22+
23+
it('should return a boolean type', () => {
24+
expect(typeof pangram('')).toBe('boolean');
25+
});
26+
27+
it.each(testCases)('should return $output', ({ input, output }) => {
28+
expect(pangram(input)).toBe(output);
29+
});
30+
});

‎README.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,17 @@ Difficulties legend:
114114

115115
<details hide>
116116
<summary>Show / Hide</summary>
117+
118+
| # | Challenge | Difficulty | My Solution |
119+
| :-: | ------------------------------------------------------------------------------------------- | :--------: | :------------------------------------------------------------------------------------------------------: |
120+
| 01 | [Contando ovejas para dormir](https://2021.adventjs.dev/challenges/01) | 🟢 | [here](https://github.com/marcode24/adventjs-solutions/tree/main/2021/01-contando-ovejas-para-dormir) |
121+
| 02 | [Ayuda al elfo a listar los regalos](https://2021.adventjs.dev/challenges/02) | 🟢 | [here](https://github.com/marcode24/adventjs-solutions/tree/main/2021/02-ayuda-al-elfo-a-listar-los-regalos) |
122+
| 05 | [Contando los dias para los regalos](https://2021.adventjs.dev/challenges/05) | 🟢 | [here](https://github.com/marcode24/adventjs-solutions/tree/main/2021/05-contando-los-dias-para-los-regalos) |
123+
| 13 | [Envuelve regalos con asteriscos](https://2021.adventjs.dev/challenges/13) | 🟢 | [here](https://github.com/marcode24/adventjs-solutions/tree/main/2021/13-envuelve-regalos-con-asteriscos) |
124+
| 16 | [Descifrando los números...](https://2021.adventjs.dev/challenges/16) | 🟢 | [here](https://github.com/marcode24/adventjs-solutions/tree/main/2021/16-descifrando-los-numeros) |
125+
| 20 | [¿Una carta de pangramas?¡QUE!](https://2021.adventjs.dev/challenges/20) | 🟢 | [here](https://github.com/marcode24/adventjs-solutions/tree/main/2021/20-una-carta-de-pangramas-que) |
126+
127+
Difficulties legend:
128+
🟢 Easy 🟡 Medium 🔴 Hard
129+
117130
</details>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /