Created
March 8, 2015 08:28
-
-
Save TGOlson/041679d57be79933bb2c to your computer and use it in GitHub Desktop.
Point-free JavaScript FizzBuzz Kata
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
var R = require('ramda'); | |
var factorOf = R.curryN(2, R.compose(R.eq(0), R.flip(R.modulo))); | |
var getFizzBuzz = R.cond( | |
[R.and(factorOf(3), factorOf(5)), R.always('FizzBuzz')], | |
[factorOf(3), R.always('Fizz')], | |
[factorOf(5), R.always('Buzz')], | |
[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
For those who may be confused by the errors they receive running this. Ramda (as of 0.17.1) has had some API changes:
I tweaked the code to work here
Thanks @TGOlson for a beautiful implementation.
Btw, I'm curious why not just: