MojiScript Fizz Buzz
# clone repository
git clone https://github.com/joelnet/MojiScript.git
# enter directory
cd MojiScript/examples/fizz-buzz
# install dependencies
npm ci
npm start
There is a very good tutorial that will walk you through the creation of this FizzBuzz app here:
Getting started with MojiScript: FizzBuzz (part 1)
Getting started with MojiScript: Async, Infinity, Testing (part 2)
import cond from 'mojiscript/logic/cond'
import pipe from 'mojiscript/core/pipe'
import map from 'mojiscript/list/map'
import range from 'mojiscript/list/range'
import allPass from 'mojiscript/logic/allPass'
const isFizz = num => num % 3 === 0
const isBuzz = num => num % 5 === 0
const isFizzBuzz = allPass ([ isFizz, isBuzz ])
const fizziness = cond ([
[ isFizzBuzz, 'FizzBuzz' ],
[ isFizz, 'Fizz' ],
[ isBuzz, 'Buzz' ],
[ () => true, x => x ]
])
const logFizziness = log => pipe ([
fizziness,
log
])
const main = ({ log }) => pipe ([
({ start, end }) => range (start) (end + 1),
map (logFizziness (log))
])
export default main