Created
January 24, 2012 23:08
-
-
Save mattflo/1673369 to your computer and use it in GitHub Desktop.
exploring coffeescript
This file contains 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
# node, jasmine, coffeescript, and rake installed/configured using | |
# steps outlined at this website: | |
# http://brizzled.clapper.org/id/117/index.html | |
# gem install guard | |
# gem install guard-shell | |
# guard init | |
# then put the following in GuardFile | |
# guard :shell do | |
# watch('.*') {`rake`} | |
# end | |
describe "primes", -> | |
examples = | |
1 : [] | |
2 : [2] | |
3 : [3] | |
4 : [2, 2] | |
5 : [5] | |
6 : [2, 3] | |
7 : [7] | |
8 : [2, 2, 2] | |
9 : [3, 3] | |
for number, expected of examples | |
it "#{number} is #{expected}", -> | |
expect(primes(number)).toEqual expected | |
primes = (number) -> | |
return [] if number == 1 | |
for divisor in [2..number] when number % divisor == 0 | |
return [divisor].concat primes(number/divisor) | |
[number] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment