Skip to content

Instantly share code, notes, and snippets.

@wazazaby
Created March 26, 2021 10:01
Show Gist options
  • Save wazazaby/d8c7e734ac35ad8cf9391cd63af6b3ff to your computer and use it in GitHub Desktop.
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 :)
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