Skip to content

Instantly share code, notes, and snippets.

@slikts
Last active December 5, 2018 11:33
Show Gist options
  • Save slikts/455bf15bbac3f191dbe749b1167dbdab to your computer and use it in GitHub Desktop.
Save slikts/455bf15bbac3f191dbe749b1167dbdab to your computer and use it in GitHub Desktop.
Enterprise edition
const Range = (a, b) => Array.from({ length: b - a }, (_, i) => a + i)
const NumTest = (n, text) => k => !(k % n) ? text : ''
const Tests = data => Object.entries(data).map(([n, text]) => NumTest(n, text))
const RangeTest = tests => n => tests.map(fn => fn(n)).join('') || n
const RangeMap = (a, b, tests) => Range(a, b).map(RangeTest(tests))
const fizzBuzz = (a, b) => RangeMap(a, b, Tests({
5: 'Fizz',
3: 'Buzz',
}))
fizzBuzz(0, 100).forEach(n => console.log(n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment