Skip to content

Instantly share code, notes, and snippets.

@StevenACoffman
Forked from buzzdecafe/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/58c77acff01aae7bea3c to your computer and use it in GitHub Desktop.
Save StevenACoffman/58c77acff01aae7bea3c to your computer and use it in GitHub Desktop.
// fizzbuzz ramda-style
var R = require('ramda');
R.forEach(R.cond([
[R.pipe(R.modulo(R.__, 15), R.equals(0)), R.always('FizzBuzz')],
[R.pipe(R.modulo(R.__, 3), R.equals(0)), R.always('Fizz')],
[R.pipe(R.modulo(R.__, 5), R.equals(0)), R.always('Buzz')],
[R.T, R.identity]
]), R.range(1, 101));
//with a helper function
var divisibleBy = R.compose(R.equals(0), R.flip(R.modulo));
R.forEach(R.cond([
[divisibleBy(15), R.always('FizzBuzz')],
[divisibleBy(3), R.always('Fizz')],
[divisibleBy(5), R.always('Buzz')],
[R.T,R.identity]
]), R.range(1, 101));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment