Skip to content

Instantly share code, notes, and snippets.

@jaloplo
Last active July 2, 2019 14:55
Show Gist options
  • Save jaloplo/bc1b0996accfaaad2324482d7afd7a6b to your computer and use it in GitHub Desktop.
Save jaloplo/bc1b0996accfaaad2324482d7afd7a6b to your computer and use it in GitHub Desktop.
// 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