-
Notifications
You must be signed in to change notification settings - Fork 0
/
walk.js
32 lines (30 loc) · 1.01 KB
/
walk.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// function isValidWalk(walk) {
// let coordinance = {'long': 0, 'wide': 0}
// if (walk.length != 10){
// return false
// } else {
// let trip = walk.forEach((direction)=> {
// switch (direction) {
// case 'n':
// coordinance.long += 1;
// break;
// case 's':
// coordinance.long -= 1;
// break;
// case 'w':
// coordinance.wide -= 1;
// break;
// case 'e':
// coordinance.wide += 1;
// }
// })
// }
// return coordinance.long === 0 && coordinance.wide === 0 ? true: false
// }
function isValidWalk(walk) {
let count = (current) => walk.filter(direction => {
return direction == current
}).length
return walk.length == 10 && count('n') === count('s') && count('w') === count('e')
}
console.log(isValidWalk(['n','s','n','s','n','s','n','s','n','s']))