-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f363a5
commit 1ac96d5
Showing
2 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |