Created
May 29, 2011 09:44
-
-
Save liammclennan/997613 to your computer and use it in GitHub Desktop.
Fizzbuzz in CoffeeScript
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
| # a type representing a number, that can be mapped to a fizzbuzz output | |
| class Value | |
| constructor: (@number) -> | |
| # calculate the correct output for the value of @number | |
| map: () -> | |
| if @_is_fizzbuzz() | |
| return 'fizzbuzz' | |
| if @_is_fizz() | |
| return 'fizz' | |
| if @_is_buzz() | |
| return 'buzz' | |
| @number | |
| _is_fizz: () -> | |
| @number % 3 == 0 | |
| _is_buzz: () -> | |
| @number % 5 == 0 | |
| _is_fizzbuzz: () -> | |
| @_is_fizz() and @_is_buzz() | |
| console.log(new Value(i).map()) for i in [1..100] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment