Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// fizzbuzz ramda-style
var R = require('ramda');
R.forEach(R.cond(
[R.pipe(R.modulo(R.__, 15), R.eq(0)), function() { console.log('FizzBuzz'); }],
[R.pipe(R.modulo(R.__, 3), R.eq(0)), function() { console.log('Fizz'); }],
[R.pipe(R.modulo(R.__, 5), R.eq(0)), function() { console.log('Buzz'); }],
[R.alwaysTrue, function(){}]
), R.range(1, 101));
// with helpers
function log(x) {
return function() {
console.log(x);
};
}
function divisibleBy(x) {
return function(y) {
return y % x === 0;
};
}
function otherwise(op) {
return [R.alwaysTrue, op];
}
function noop(){}
R.forEach(R.cond(
[divisibleBy(15), log('FizzBuzz')],
[divisibleBy(3), log('Fizz')],
[divisibleBy(5), log('Buzz')],
otherwise(noop)
), R.range(1, 101));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment