Last active
July 2, 2019 14:55
-
-
Save jaloplo/bc1b0996accfaaad2324482d7afd7a6b to your computer and use it in GitHub Desktop.
// source https://jsbin.com/ligixeb
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 is a solution for the **Daily Challenge #5 - Ten Minute Walk** challenge | |
// The link to reach this is https://dev.to/thepracticaldev/daily-challenge-5-ten-minute-walk-1188 | |
function getWalkSteps(walkTime) { | |
if(walkTime % 2 > 0) { | |
throw new Error('You cannot come back'); | |
} | |
const distance = walkTime/2; | |
const x = Math.floor(Math.random(distance) * distance); | |
const y = distance - x; | |
return new Array(walkTime) | |
.fill('e', 0, x) | |
.fill('n', x, x+y) | |
.fill('w', x+y, x+y+x) | |
.fill('s', x+y+x, x+y+x+y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment