Skip to content

Commit f19d53d

Browse files
authored
Merge pull request #20 from marcode24/2024-02
2024 02
2 parents 9cb4f1e + 1888131 commit f19d53d

File tree

5 files changed

+91
-3
lines changed

5 files changed

+91
-3
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ module.exports = {
1717
'no-param-reassign': 'off',
1818
'no-unused-expressions': 'off',
1919
'no-return-assign': 'off',
20+
'operator-linebreak': ['error', 'before'],
2021
},
2122
};

2024/02-enmarcando-nombres/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Reto 02: Enmarcando-nombres
2+
3+
**Santa Claus** 🎅 quiere enmarcar los nombres de los niños buenos para decorar su taller 🖼️, pero el marco debe cumplir unas reglas específicas. Tu tarea es ayudar a los elfos a generar este marco mágico.
4+
5+
**Reglas:**
6+
7+
Dado un array de nombres, debes crear un marco rectangular que los contenga a todos.
8+
Cada nombre debe estar en una línea, alineado a la izquierda.
9+
El marco está construido con * y tiene un borde de una línea de ancho.
10+
La anchura del marco se adapta automáticamente al nombre más largo más un margen de 1 espacio a cada lado.
11+
12+
Ejemplo de funcionamiento:
13+
14+
```js
15+
createFrame(['midu', 'madeval', 'educalvolpz'])
16+
17+
// Resultado esperado:
18+
***************
19+
* midu *
20+
* madeval *
21+
* educalvolpz *
22+
***************
23+
24+
createFrame(['midu'])
25+
26+
// Resultado esperado:
27+
********
28+
* midu *
29+
********
30+
31+
createFrame(['a', 'bb', 'ccc'])
32+
33+
// Resultado esperado:
34+
*******
35+
* a *
36+
* bb *
37+
* ccc *
38+
*******
39+
40+
createFrame(['a', 'bb', 'ccc', 'dddd'])
41+
```

2024/02-enmarcando-nombres/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function createFrame(names) {
2+
const maxLength = Math.max(...names.map((name) => name.length));
3+
const border = '*'.repeat(maxLength + 4);
4+
const framedNames = names.map((name) => `* ${name.padEnd(maxLength, ' ')} *`);
5+
6+
return [border, ...framedNames, border].join('\n');
7+
}
8+
9+
module.exports = createFrame;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const createFrame = require('./index');
2+
3+
describe('02 => Enmarcando-nombres', () => {
4+
const TEST_CASES = [
5+
{
6+
input: ['midu'],
7+
output: '********\n* midu *\n********',
8+
},
9+
{
10+
input: ['midu', 'madeval', 'educalvolpz'],
11+
output:
12+
'***************\n* midu *\n* madeval *\n* educalvolpz *\n***************',
13+
},
14+
{
15+
input: ['a', 'bb', 'ccc'],
16+
output: '*******\n* a *\n* bb *\n* ccc *\n*******',
17+
},
18+
{
19+
input: ['midu', 'madeval', 'educalvolpz', 'midu'],
20+
output:
21+
'***************\n* midu *\n* madeval *\n* educalvolpz *\n* midu *\n***************',
22+
},
23+
];
24+
25+
it('should return an array type', () => {
26+
const { input } = TEST_CASES[0];
27+
expect(typeof createFrame(input)).toBe('string');
28+
});
29+
30+
it.each(TEST_CASES)(
31+
'should return the correct frame',
32+
({ input, output }) => {
33+
expect(createFrame(input)).toBe(output);
34+
},
35+
);
36+
});

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ npm run test 'year'/'challenge'/index.test.js
5757
<details open>
5858
<summary>Show / Hide</summary>
5959

60-
| # | Challenge | Difficulty | My Solution | My Score |
61-
| :-: | ------------------------------------------------------------------------------------------- | :--------: | :------------------------------------------------------------------------------------------------------------: | :-----------: |
62-
| 01 | [🎁 ¡Primer regalo repetido!](https://adventjs.dev/es/challenges/2024/1) | 🟢 | [here](./2024/01-primer-regalo-repetido/index.js) | ⭐⭐⭐⭐⭐ |
60+
| # | Challenge | Difficulty | My Solution | My Score |
61+
| :-: | ------------------------------------------------------------------------------------------- | :--------: | :--------------------------------------------------------------------------------------------------------: | :-----------: |
62+
| 01 | [🎁 ¡Primer regalo repetido!](https://adventjs.dev/es/challenges/2024/1) | 🟢 | [here](./2024/01-primer-regalo-repetido/index.js) | ⭐⭐⭐⭐⭐ |
63+
| 02 | [🖼️ Enmarcando nombres](https://adventjs.dev/es/challenges/2024/2) | 🟢 | [here](./2024/02-enmarcando-nombres/index.js) | ⭐⭐⭐⭐⭐ |
6364

6465
Difficulties legend:
6566
🟢 Easy 🟡 Medium 🔴 Hard

0 commit comments

Comments
 (0)