Created
June 25, 2018 08:44
-
-
Save ryu1-1uyr/8163669a97a9de4ac6665cd628f1212c to your computer and use it in GitHub Desktop.
クロージャーと抽象関数つかったfizzbuzz、fizzbuzz関数をクロージャーで作ってるのは甘え<=
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
const fizzbuzz = (v) => { | |
const origin = num => word => inputnum => { | |
return inputnum % num == 0 ? word : inputnum; | |
} | |
const fizz = origin(3)('Fizz') | |
const buzz = origin(5)('Buzz') | |
const fizzbuzz = origin(15)('FizzBuzz') | |
//const fizz = x => x%3==0?'Fizz':x; | |
//const buzz = x => x%5==0?'Buzz':x; | |
return buzz(fizz(fizzbuzz(v))) | |
} | |
// const origin = num => word => inputnum => { | |
// return inputnum % num == 0 ? word : inputnum; | |
// } | |
for (let i = 1; i< 31;i++){ | |
console.log(fizzbuzz(i)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment