Skip to content

Instantly share code, notes, and snippets.

@StevenACoffman
Forked from TGOlson/fizzbuzz.js
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StevenACoffman/3631e4dacecd9ccbc6ca to your computer and use it in GitHub Desktop.
Save StevenACoffman/3631e4dacecd9ccbc6ca to your computer and use it in GitHub Desktop.
Point-free JavaScript FizzBuzz Kata
var R = require('ramda');
var factorOf = R.compose(R.equals(0), R.flip(R.modulo));
var getFizzBuzz = R.cond([
[factorOf(15), R.always('FizzBuzz')],
[factorOf(5), R.always('Buzz')],
[factorOf(3), R.always('Fizz')],
[R.T, R.identity]
]);
var fizzBuzz = R.compose(R.map(getFizzBuzz), R.times(R.inc));
fizzBuzz(15);
// => [ 1, 2, 'Fizz', 4, 'Buzz', 'Fizz', 7, 8, 'Fizz', 'Buzz', 11, 'Fizz', 13, 14, 'FizzBuzz' ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment