Created
November 28, 2013 00:23
-
-
Save mantisbayne/7685360 to your computer and use it in GitHub Desktop.
Codecademy trouble
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
$VERBOSE = nil # We'll explain this at the end of the lesson. | |
require 'prime' # This is a module. We'll cover these soon! | |
def first_n_primes(n) | |
unless n.is_a? Integer | |
return "n must be an integer." | |
end | |
if n <= 0 | |
return "n must be greater than 0." | |
end | |
prime_array = [] if prime_array.nil? | |
prime = Prime.new | |
for num in (1..n) | |
prime_array.push(prime.next) | |
end | |
return prime_array | |
end | |
first_n_primes(10) |
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
prime_array ||= [] | |
return "n must be an integer." unless n.is_a? Integer | |
return "n must be greater than 0." if n <= 0 | |
They want me to remove the unnecessary 'return', but I keep getting errors, no matter what I try |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment