Skip to content

Instantly share code, notes, and snippets.

@neharkarvishal
Created June 13, 2021 13:05
Show Gist options
  • Save neharkarvishal/da15fa3c5329e17f969accf3a9855ede to your computer and use it in GitHub Desktop.
Save neharkarvishal/da15fa3c5329e17f969accf3a9855ede to your computer and use it in GitHub Desktop.
function fizzBuzz(n: number) {
return (
{ true: '', false: 'Fizz' }[`${n % 3 === 0}`] +
{ true: '', false: 'Buzz' }[`${n % 5 === 0}`] ||
n.toString()
)
}
function fizzBuzzFunctional(n: number) {
let test =
(d: number, s: 'Fizz' | 'Buzz', x: Function) =>
n % d === 0
? () => s + x('')
: x
let fizz = (x: Function) => test(3, 'Fizz', x)
let buzz = (x: Function) => test(5, 'Buzz', x)
return fizz( buzz(x => x) )( n.toString() )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment