Created
June 13, 2021 13:05
-
-
Save neharkarvishal/da15fa3c5329e17f969accf3a9855ede to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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