Module: JobInterview::Fibonacci

Included in:
Answer
Defined in:
lib/job_interview/fibonacci.rb

Instance Method Summary collapse

Instance Method Details

#fib(n, *args) ⇒ Object

args should be the strategy to be used (one of :iterative, :recursive) Defaults to recursive



8
9
10
11
12
13
14
15
16
17
# File 'lib/job_interview/fibonacci.rb', line 8

def fib(n, *args)
  if args && args.include?(:iterative)
    iterative_fib(n)
  else
    ## TODO: make this efficient
    return Array.new(n) {|i| recursive_fib(i + 1) }

  end

end