Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const isValidWalk = (walk) => {
- let coords = [0, 0];
- let time = 0;
- walk.forEach(dir => {
- switch (dir) {
- case 'n':
- coords[0]++;
- time++;
- break;
- case 's':
- coords[0]--;
- time++;
- break;
- case 'e':
- coords[1]++;
- time++;
- break;
- case 'w':
- coords[1]--;
- time++;
- break;
- }
- });
- if (time == 10) {
- if (coords[0] == 0 && coords[1] == 0) {
- return true;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement