brianhaveri/Underscore.php

Memoize example doesn't work

Opened this issue · 0 comments

The example for __::memoize doesn't work:

$fibonacci = function($n) use (&$fibonacci) {
  return $n < 2 ? $n : $fibonacci($n - 1) + $fibonacci($n - 2);
};
$fastFibonacci = __::memoize($fibonacci);

Computing $fastFibonacci(40) is no faster than $fibonacci(40), since $fibonacci calls into itself. Instead, the example should set $fibonacci = __::memoize($fibonacci) so that it calls into the memoized version.