-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Descripción | ||
|
||
¡Hay demasiados regalos 🎁! Y envolverlos es una locura... | ||
|
||
Vamos a crear una función que pasándole un array de regalos, nos devuelva otro array pero donde todos los regalos han sido envueltos con asteriscos tanto por arriba como por los lados. | ||
|
||
Sólo tienes que tener en cuenta unas cosillas ✌️: | ||
|
||
Si el array está vacío, devuelve un array vacío | ||
Los regalos son emojis 🎁... por lo que tenlo en cuenta a la hora de contar su longitud... | ||
Por suerte, cada posición del array siempre tiene la misma longitud... | ||
|
||
```js | ||
wrapGifts(['📷', '⚽️']); | ||
/* Resultado: | ||
[ '****', | ||
'*📷*', | ||
'*⚽️*', | ||
'****' | ||
] | ||
*/ | ||
|
||
wrapGifts(['🏈🎸', '🎮🧸']); | ||
/* Resultado: | ||
[ '******', | ||
'*🏈🎸*', | ||
'*🎮🧸*', | ||
'******' | ||
] | ||
*/ | ||
|
||
wrapGifts(['📷']); | ||
/* Resultado: | ||
[ '****', | ||
'*📷*', | ||
'****' | ||
] | ||
*/ | ||
``` |
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 @@ | ||
export default function wrapGifts(gifts) { | ||
const [firstGift] = gifts; | ||
const length = firstGift.length; | ||
const asterisks = '*'.repeat(length + 2); | ||
const wrappedGifts = [asterisks]; | ||
gifts.forEach(gift => wrappedGifts.push(`*${gift}*`)); | ||
wrappedGifts.push(asterisks); | ||
return wrappedGifts; | ||
} |