Skip to content

Instantly share code, notes, and snippets.

@ryu1-1uyr
Created April 3, 2019 02:13
Show Gist options
  • Save ryu1-1uyr/af74b08f726d37c1dbf17aacf6b07be3 to your computer and use it in GitHub Desktop.
Save ryu1-1uyr/af74b08f726d37c1dbf17aacf6b07be3 to your computer and use it in GitHub Desktop.
メソッドチェーンっぽい書き方をしてみたかった
Number.prototype.fizz = function fizz () {
if (this % 3 == 0) {
return "Fizz"
} else {
return this
}
}
Number.prototype.buzz = function buzz () {
if (this % 5 == 0) {
return "Buzz"
} else {
return this
}
}
Number.prototype.fizzbuzz = function fizzbuzz () {
if (this % 15 == 0) {
return "FizzBuzz"
} else {
return this
}
}
Number.prototype.identity = function identity () {return this}
String.prototype.fizz = function fizz () {return this}
String.prototype.buzz = function buzz () {return this}
String.prototype.identity = function identity () {return this}
const output = [...Array(30).keys()].map(x=>x+1).map(x=>x.fizzbuzz().fizz().buzz().identity())
console.log(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment