Skip to content

Instantly share code, notes, and snippets.

@mattflo
Created January 24, 2012 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattflo/1673369 to your computer and use it in GitHub Desktop.
Save mattflo/1673369 to your computer and use it in GitHub Desktop.
exploring coffeescript
# 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