This is embarrassing, I don’t get why this line of code isn’t returning to me the Fibonnacci series, but instead just a series of ones.
(1..5).inject([1]) { |arr, x| x > 1 ? arr << arr.last + arr.last-1 : arr << 1; arr }
The code above is supposed to find the 1st six numbers in the series.
Could you please tell me what am I doing wrong?
Thank you as always.
arr.last-1 doesnt work, try arr[-2] instead:
-edit-
btw you don’t need that ;arr at the end, << returns the array by default