6 "Final Push"


#1

I am really stuck on how to correctly change the .push to a <<, and there are no hints given for this exercise. Please could someone talk me through how to make the necessary changes to the below code. Thanks!

Original Code
prime = Prime.new
n.times{prime_array.push(prime.next)}
prime_array
end


#2

Hi, you should put it after prime_array

prime_array ||= []  
  prime = Prime.new
  n.times {prime_array << (prime.next)}
  prime_array
end

first_n_primes(10)

#3

Thanks for such a quick response- the code worked perfectly!


#4

Hi,
Why do you keep the () around prime.next ?
The line :
n.times {prime_array << prime.next}

worked just fine for me.


#5

Hi you could add the () if you want it doesn't change anything.


#6

In the spirit of having a cleaner code and while abiding to the Ruby standards which option is the best?
With or Without the () ?


#7

I think its better without.


#8

thanx, that is helpfull