Module: ScraperUtils::MathsUtils

Defined in:
lib/scraper_utils/maths_utils.rb

Overview

Misc Maths Utilities

Class Method Summary collapse

Class Method Details

.fibonacci_series(max) ⇒ Array<Integer>

Generate a fibonacci series

Parameters:

  • max (Integer)

    The max the sequence goes up to

Returns:

  • (Array<Integer>)

    The fibonacci numbers up to max



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/scraper_utils/maths_utils.rb', line 11

def self.fibonacci_series(max)
  result = []
  # Start with the basic Fibonacci sequence
  last_fib, this_fib = 1, 0
  while this_fib <= max
    result << this_fib
    yield this_fib if block_given?
    last_fib, this_fib = this_fib, this_fib + last_fib
  end
  result
end