Skip to content

Instantly share code, notes, and snippets.

@jmonterroso
Last active August 4, 2017 18:14
Show Gist options
  • Save jmonterroso/f750496a249f3116a55aaa2e571147ed to your computer and use it in GitHub Desktop.
Save jmonterroso/f750496a249f3116a55aaa2e571147ed to your computer and use it in GitHub Desktop.
Katas Solve

All Katas solved and snippets

Format number to currency

ES 6

let formatMoney = (amount) => `$${amount.toFixed(2)}`

Take a Ten Minute Walk

You live in the city of Cartesia where all roads are laid out in a perfect grid. You arrived ten minutes too early to an appointment, so you decided to take the opportunity to go for a short walk. The city provides its citizens with a Walk Generating App on their phones -- everytime you press the button it sends you an array of one-letter strings representing directions to walk (eg. ['n', 's', 'w', 'e']). You know it takes you one minute to traverse one city block, so create a function that will return true if the walk the app gives you will take you exactly ten minutes (you don't want to be early or late!) and will, of course, return you to your starting point. Return false otherwise.

Note: you will always receive a valid array containing a random assortment of direction letters ('n', 's', 'e', or 'w' only). It will never give you an empty array (that's not a walk, that's standing still!).


function isValidWalk(walk) {
  const north = walk.filter(item => { return item === "n" }).length;
  const south = walk.filter(item => { return item === "s" }).length;
  const east = walk.filter(item => { return item === "e" }).length;
  const west = walk.filter(item => { return item === "w" }).length;
  
  return walk.length === 10 && north === south && east === west;
}


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment