Skip to content

Commit 3eccb30

Browse files
committed
Solución Reto 8
1 parent cfd6cce commit 3eccb30

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

retos/reto-8/main.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function organizeGifts(gifts) {
2+
const countGifts = gifts.match(/\d+/g)
3+
const nameGifts = gifts.match(/[^0-9]/g)
4+
5+
let response = ""
6+
let i = 0
7+
8+
for (let c of countGifts) {
9+
const g = nameGifts[i]
10+
let a = ""
11+
12+
c = +c
13+
14+
a += `[${g}]`.repeat(c / 50)
15+
c %= 50
16+
17+
a += `{${g}}`.repeat(c / 10)
18+
c %= 10
19+
20+
a += `(${g.repeat(c)})`.repeat(+!!c)
21+
22+
response += a
23+
i++
24+
}
25+
26+
return response
27+
}
28+
29+
module.exports = organizeGifts

0 commit comments

Comments
 (0)