Last active
August 29, 2015 14:09
-
-
Save buzzdecafe/db39615536be4c9b7c3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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