Created
April 3, 2019 02:13
-
-
Save ryu1-1uyr/af74b08f726d37c1dbf17aacf6b07be3 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
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