Skip to content

Commit

Permalink
Merge pull request #20 from marcode24/2024-02
Browse files Browse the repository at this point in the history
2024 02
  • Loading branch information
marcode24 authored Dec 2, 2024
2 parents 9cb4f1e + 1888131 commit f19d53d
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 3 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ module.exports = {
'no-param-reassign': 'off',
'no-unused-expressions': 'off',
'no-return-assign': 'off',
'operator-linebreak': ['error', 'before'],
},
};
41 changes: 41 additions & 0 deletions 2024/02-enmarcando-nombres/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Reto 02: Enmarcando-nombres

**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.

**Reglas:**

Dado un array de nombres, debes crear un marco rectangular que los contenga a todos.
Cada nombre debe estar en una línea, alineado a la izquierda.
El marco está construido con * y tiene un borde de una línea de ancho.
La anchura del marco se adapta automáticamente al nombre más largo más un margen de 1 espacio a cada lado.

Ejemplo de funcionamiento:

```js
createFrame(['midu', 'madeval', 'educalvolpz'])

// Resultado esperado:
***************
* midu *
* madeval *
* educalvolpz *
***************

createFrame(['midu'])

// Resultado esperado:
********
* midu *
********

createFrame(['a', 'bb', 'ccc'])

// Resultado esperado:
*******
* a *
* bb *
* ccc *
*******

createFrame(['a', 'bb', 'ccc', 'dddd'])
```
9 changes: 9 additions & 0 deletions 2024/02-enmarcando-nombres/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function createFrame(names) {
const maxLength = Math.max(...names.map((name) => name.length));
const border = '*'.repeat(maxLength + 4);
const framedNames = names.map((name) => `* ${name.padEnd(maxLength, ' ')} *`);

return [border, ...framedNames, border].join('\n');
}

module.exports = createFrame;
36 changes: 36 additions & 0 deletions 2024/02-enmarcando-nombres/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const createFrame = require('./index');

describe('02 => Enmarcando-nombres', () => {
const TEST_CASES = [
{
input: ['midu'],
output: '********\n* midu *\n********',
},
{
input: ['midu', 'madeval', 'educalvolpz'],
output:
'***************\n* midu *\n* madeval *\n* educalvolpz *\n***************',
},
{
input: ['a', 'bb', 'ccc'],
output: '*******\n* a *\n* bb *\n* ccc *\n*******',
},
{
input: ['midu', 'madeval', 'educalvolpz', 'midu'],
output:
'***************\n* midu *\n* madeval *\n* educalvolpz *\n* midu *\n***************',
},
];

it('should return an array type', () => {
const { input } = TEST_CASES[0];
expect(typeof createFrame(input)).toBe('string');
});

it.each(TEST_CASES)(
'should return the correct frame',
({ input, output }) => {
expect(createFrame(input)).toBe(output);
},
);
});
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ npm run test 'year'/'challenge'/index.test.js
<details open>
<summary>Show / Hide</summary>

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

Difficulties legend:
🟢 Easy 🟡 Medium 🔴 Hard
Expand Down

0 comments on commit f19d53d

Please sign in to comment.