During my reflexion about this challenge, I figured out that if input is an odd number, you will never be able to go back at your start position.
Here my JS implementation:
functiondirection(time){if(time%2>0){throw'You will never go back!!';}constahead=Math.ceil(time/4),turn=Math.floor(time/4);return('n'.repeat(ahead)+'w'.repeat(turn)+'s'.repeat(ahead)+'e'.repeat(turn)).split('');}// let's test ittry{console.log(direction(4));// print ["n", "w", "s", "e"]}catch(e){console.log(e);}try{console.log(direction(1));}catch(e){console.log(e);// You will never go back!!}try{console.log(direction(3));}catch(e){console.log(e);// You will never go back!!}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
During my reflexion about this challenge, I figured out that if input is an odd number, you will never be able to go back at your start position.
Here my JS implementation: