-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from marcode24/2024-02
2024 02
- Loading branch information
Showing
5 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters