forked from rmetzler/litcoffee-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fizzbuzz.litcoffee
executable file
·38 lines (25 loc) · 1.1 KB
/
fizzbuzz.litcoffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#! /usr/bin/env coffee
# fizzbuzz.litcoffee
This is the fizzbuzz test in literate CoffeeScript.
## What should FizzBuzz do?
The FizzBuzz test should print:
- 'fizz' for every number dividable by 3,
- 'buzz' for every number dividable by 5,
- 'fizzbuzz' if the number is dividable by 3 and 5
- else: just print the number.
## Fun Facts
FizzBuzz is commonly used to interview programmers and test their coding skills.
Once the author [@rmetzler](http://github.com/rmetzler) was asked on a job interview
to write a "coding test". He answered by asking if the meant test was FizzBuzz. The interviewer
said yes and made a statement to not test the interviewee. The author later learned he didn't
get the job, was sad and decided on writing FizzBuzz as a learning tool.
## FizzBuzz in CoffeeScript
FizzBuzz in CoffeeScript could look like this:
fizzbuzz = (number) ->
return 'fizzbuzz' if 0 == number % 15
return 'buzz' if 0 == number % 5
return 'fizz' if 0 == number % 3
number.toString()
for x in [1..100]
# pretty print
console.log "#{x}\t->\t#{fizzbuzz x}"