Skip to content

Instantly share code, notes, and snippets.

@liammclennan
Created May 29, 2011 09:44
Show Gist options
  • Select an option

  • Save liammclennan/997613 to your computer and use it in GitHub Desktop.

Select an option

Save liammclennan/997613 to your computer and use it in GitHub Desktop.
Fizzbuzz in CoffeeScript
# 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