-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReto #3.js
More file actions
65 lines (55 loc) · 1.38 KB
/
Reto #3.js
File metadata and controls
65 lines (55 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* Reto #3: 👶 Ayuda al becario
*
* En el taller de Santa hay un elfo becario que está aprendiendo a envolver regalos 🎁.
Le han pedido que envuelva cajas usando solo texto… y lo hace más o menos bien.
Le pasan dos parámetros:
size: el tamaño del regalo cuadrado
symbol: el carácter que el elfo usa para hacer el borde (cuando no se equivoca 😅)
El regalo debe cumplir:
Debe ser un cuadrado de size x size.
El interior siempre está vacío (lleno de espacios), porque el elfo "aún no sabe dibujar el relleno".
Si size < 2, devuelve una cadena vacía: el elfo lo intentó, pero se le perdió el regalo.
El resultado final debe ser un string con saltos de línea \n.
Sí, es un reto fácil… pero no queremos que despidan al becario. ¿Verdad?
🧩 Ejemplos
*/
const g1 = drawGift(4, '*')
console.log(g1)
/*
****
* *
* *
****
*/
const g2 = drawGift(3, '#')
console.log(g2)
/*
###
# #
###
*/
const g3 = drawGift(2, '-')
console.log(g3)
/*
--
--
*/
const g4 = drawGift(1, '+')
console.log(g4)
// "" pobre becario…
/**
* @param {number} size - The size of the gift
* @param {string} symbol - The symbol to draw
* @returns {string} The gift drawn
*/
function drawGift(size, symbol) {
if(size <=1)
return '';
let ans=symbol.repeat(size)+'\n';
for(let i=0; i<size-2;i++){
ans+=symbol+' '.repeat(size-2)+symbol+'\n';
}
ans+=symbol.repeat(size);
return ans;
}