Created
March 26, 2021 10:01
-
-
Save wazazaby/d8c7e734ac35ad8cf9391cd63af6b3ff to your computer and use it in GitHub Desktop.
Simple FizzBuzz using the Ramda library. Let me know if anything can be implemented in a better way :)
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
import R from 'ramda'; | |
const isModulo = R.curry(R.pipe(R.flip(R.modulo), R.equals(0))); | |
const fizzbuzz = R.pipe( | |
R.add(1), | |
R.range(1), | |
R.map( | |
R.cond([ | |
[R.both(isModulo(3), isModulo(5)), R.always('FizzBuzz')], | |
[isModulo(3), R.always('Fizz')], | |
[isModulo(5), R.always('Buzz')], | |
[R.T, R.identity] | |
]) | |
), | |
R.join('\n') | |
); | |
const result = fizzbuzz(15); | |
console.log(result) | |
// Outputs | |
// 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