To be or not to be (th refactor factory)


#1

Hello everybody!!!
Something I coded finds infinite loops! What should I do ? What's wrong?

$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 ||=

prime = Prime.new
for num in (1..n)
prime_array.push(prime.next)
end
prime_array
end

first_n_primes(10)

Thank you in advance!!!


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.