Skip to content

Commit

Permalink
reto-8
Browse files Browse the repository at this point in the history
  • Loading branch information
fernargdev committed Dec 15, 2023
1 parent 623da79 commit 2798391
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions retos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<!-- <script src="reto-4.js"></script> -->
<!-- <script src="reto-5.js"></script> -->
<!-- <script src="reto-6.js"></script> -->
<!-- <script src="reto-7.js"></script> -->
<script src="reto-8.js"></script>
</body>

</html>
31 changes: 31 additions & 0 deletions retos/reto-8.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* eslint-disable space-before-function-paren */
function organizeGifts(gifts) {
const countGifts = gifts.match(/\d+/g)
const nameGifts = gifts.match(/[^0-9]/g)

let response = ''
let i = 0

for (let c of countGifts) {
const g = nameGifts[i]
let a = ''

c = +c

a += `[${g}]`.repeat(c / 50)
c %= 50

a += `{${g}}`.repeat(c / 10)
c %= 10

a += `(${g.repeat(c)})`.repeat(+!!c)

response += a
i++
}

return response
}

// const result1 = organizeGifts('76a11b')
// console.log(result1)

0 comments on commit 2798391

Please sign in to comment.