Skip to content

Commit

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

</html>
27 changes: 27 additions & 0 deletions retos/reto-5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* eslint-disable no-useless-escape */
/* eslint-disable space-before-function-paren */
/* eslint-disable no-unused-vars */
function cyberReindeer(road, time) {
const snapshots = [road]
let lastChar = '.'

for (let i = 1; i < time; i++) {
if (i === 5) road = road.replaceAll('|', '*')

const matches = road.match(/S[\*\.]/g)

if (matches) {
road = road.replace(matches[0], lastChar + 'S')
lastChar = matches[0][1]
}

snapshots.push(road)
}

return snapshots
}

const road = 'S..|...|..'
const time = 10

console.log(cyberReindeer(road, time))

0 comments on commit 1ac96d5

Please sign in to comment.