From a96e10d53cdadad528bb8d8e5618343c0a13e5e5 Mon Sep 17 00:00:00 2001 From: Marco Cruz Date: Sun, 1 Dec 2024 20:13:02 -0600 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9C=A8=20Add=20challenge-02=20solution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2024/02-enmarcando-nombres/README.md | 41 ++++++++++++++++++++++++ 2024/02-enmarcando-nombres/index.js | 9 ++++++ 2024/02-enmarcando-nombres/index.test.js | 36 +++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 2024/02-enmarcando-nombres/README.md create mode 100644 2024/02-enmarcando-nombres/index.js create mode 100644 2024/02-enmarcando-nombres/index.test.js diff --git a/2024/02-enmarcando-nombres/README.md b/2024/02-enmarcando-nombres/README.md new file mode 100644 index 0000000..cf00f0b --- /dev/null +++ b/2024/02-enmarcando-nombres/README.md @@ -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']) +``` diff --git a/2024/02-enmarcando-nombres/index.js b/2024/02-enmarcando-nombres/index.js new file mode 100644 index 0000000..6a544ed --- /dev/null +++ b/2024/02-enmarcando-nombres/index.js @@ -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; diff --git a/2024/02-enmarcando-nombres/index.test.js b/2024/02-enmarcando-nombres/index.test.js new file mode 100644 index 0000000..c4a3e2b --- /dev/null +++ b/2024/02-enmarcando-nombres/index.test.js @@ -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); + }, + ); +}); From 65ac7f1e9e5f202d2b37f5492c444da27255fee4 Mon Sep 17 00:00:00 2001 From: Marco Cruz Date: Sun, 1 Dec 2024 20:13:17 -0600 Subject: [PATCH 2/4] =?UTF-8?q?=E2=9C=A8=20Update=20ESLint=20configuration?= =?UTF-8?q?=20to=20enforce=20operator=20linebreak=20style?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc.js | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.js b/.eslintrc.js index 8840319..2942fed 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -17,5 +17,6 @@ module.exports = { 'no-param-reassign': 'off', 'no-unused-expressions': 'off', 'no-return-assign': 'off', + 'operator-linebreak': ['error', 'after'], }, }; From b0c62f1bcc1e72cdc57339af4aedc303ebba3218 Mon Sep 17 00:00:00 2001 From: Marco Cruz Date: Sun, 1 Dec 2024 20:13:29 -0600 Subject: [PATCH 3/4] =?UTF-8?q?=E2=9C=A8=20Update=20README=20to=20include?= =?UTF-8?q?=20challenge-02=20and=20adjust=20table=20formatting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a5390ad..907e1a8 100644 --- a/README.md +++ b/README.md @@ -57,9 +57,10 @@ npm run test 'year'/'challenge'/index.test.js
Show / Hide -| # | 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 From 18881314b6b6289689e3f83c391b45b43b805c67 Mon Sep 17 00:00:00 2001 From: Marco Cruz Date: Sun, 1 Dec 2024 20:16:06 -0600 Subject: [PATCH 4/4] =?UTF-8?q?=E2=9C=A8=20Update=20ESLint=20configuration?= =?UTF-8?q?=20to=20change=20operator=20linebreak=20style=20to=20'before'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 2942fed..7517ee0 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -17,6 +17,6 @@ module.exports = { 'no-param-reassign': 'off', 'no-unused-expressions': 'off', 'no-return-assign': 'off', - 'operator-linebreak': ['error', 'after'], + 'operator-linebreak': ['error', 'before'], }, };