Skip to content

Instantly share code, notes, and snippets.

@ryu1-1uyr
Created June 25, 2018 08:44
Show Gist options
  • Save ryu1-1uyr/8163669a97a9de4ac6665cd628f1212c to your computer and use it in GitHub Desktop.
Save ryu1-1uyr/8163669a97a9de4ac6665cd628f1212c to your computer and use it in GitHub Desktop.
クロージャーと抽象関数つかったfizzbuzz、fizzbuzz関数をクロージャーで作ってるのは甘え<=
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