-
-
Save StevenACoffman/3631e4dacecd9ccbc6ca 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.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