Advertisement
gasaichan

Untitled

Nov 14th, 2019
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const isValidWalk = (walk) => {
  2.   let coords = [0, 0];
  3.   let time = 0;
  4.   walk.forEach(dir => {
  5.   switch (dir) {
  6.       case 'n':
  7.         coords[0]++;
  8.         time++;
  9.         break;
  10.       case 's':
  11.         coords[0]--;
  12.         time++;
  13.         break;
  14.       case 'e':
  15.         coords[1]++;
  16.         time++;
  17.         break;
  18.       case 'w':
  19.         coords[1]--;
  20.         time++;
  21.         break;
  22.     }
  23.   });
  24.  
  25.   if (time == 10) {
  26.     if (coords[0] == 0 && coords[1] == 0) {
  27.       return true;
  28.     }
  29.   }
  30.  
  31.   return false;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement