Skip to content

Instantly share code, notes, and snippets.

@misterussell
Created June 14, 2017 20:34
Show Gist options
  • Save misterussell/d8cb74e1e5dd9279e95dd4af6a51a3ce to your computer and use it in GitHub Desktop.
Save misterussell/d8cb74e1e5dd9279e95dd4af6a51a3ce to your computer and use it in GitHub Desktop.
Codewars Test 2
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