Skip to content

Instantly share code, notes, and snippets.

@coderbyheart
Last active August 26, 2016 10:00
Show Gist options
  • Save coderbyheart/35ae09cde55c67735a6b7ec27e5a474c to your computer and use it in GitHub Desktop.
Save coderbyheart/35ae09cde55c67735a6b7ec27e5a474c to your computer and use it in GitHub Desktop.
pokemon-kata.js
it("should find the name of the nearest Pokemon", () => {
const monNames = pluck('name')
const monDistances = R.pipe(pluck('position'), map(distance(playerPosition)))
const nameAndDistancePair = curryN(2, zip)(
monNames(mons),
monDistances(mons)
)
const nearestMon = R.reduce((mon, nearestMon) => {
return mon[1] < nearestMon[1] ? mon : nearestMon
}, Infinity)
const nearestPokemonName = R.pipe(nearestMon, nth(0))
expect(nearestPokemonName(nameAndDistancePair)).toEqual('Magikarp')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment