I came across this excellent piece of code over at http://projecteuler.net/ but I’m having trouble wrapping my mind around a certain part of it.
def generate(n, factors=[])
return factors if n == 1
new_factor = (2..n).find {|f| n % f == 0}
generate(n / new_factor, factors << [new_factor])
end
factors = []
generate(4356463234, factors)
Question: When the generate function calls upon itself in line 4, what does factors << [new_factor] do?
Thank you for your insight!
It appends
[new_factor]to the end of thefactorsarray.