Created
June 14, 2017 20:34
-
-
Save misterussell/d8cb74e1e5dd9279e95dd4af6a51a3ce to your computer and use it in GitHub Desktop.
Codewars Test 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isValidWalk(walk) { | |
let compass = {}; | |
walk.forEach((direction, i) => { | |
if (compass[direction]) { | |
compass[direction] += 1; | |
} else { | |
compass[direction] = 1; | |
} | |
}); | |
if (compass.n !== compass.s || compass.e !== compass.w) { | |
return false; | |
} else if (walk.length > 10 || walk.length < 10) { | |
return false; | |
} else return true; | |
} | |
console.log(isValidWalk(['n','s','n','s','n','s','n','s','n','s'])); | |
console.log(isValidWalk(['w','e','w','e','w','e','w','e','w','e','w','e'])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment