Skip to content

Commit

Permalink
feat: Add solution challenge 13
Browse files Browse the repository at this point in the history
  • Loading branch information
neftdev committed Dec 14, 2021
1 parent 0f3044d commit 4fd28c7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
39 changes: 39 additions & 0 deletions challenge-13/README.md
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:
[ '****',
'*📷*',
'****'
]
*/
```
9 changes: 9 additions & 0 deletions challenge-13/solution.js
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;
}

0 comments on commit 4fd28c7

Please sign in to comment.