I want to generate fibonacci series in ruby, till the max hits a max value say 50000. I wrote the following snippet:
high = 50000
arr = [0, 1]
while arr.last < high do
arr.inject{|a, i| arr.push(arr[-2] + arr[-1])}
end
puts arr.last
This causes the program to halt.
I am actually new to ruby, Is there a good way to tackle ifs and while with inject
in the same statement in ruby?
What could be a better approach for the above method i am using.