documentcloud/underscore — Issue #339: Fast Fibonacci function in the (online) docs is not a real fast fibonacci
Author: yuchi
Created: 2011-10-19 07:54:12+00:00
State: open

As stated in the subject.

Actual implementation (not fast):

```javascript
var fibonacci = function(n) {
return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2);
};
var fastFibonacci = _.memoize(fibonacci);
```

Correct one (fast):

```javascript
var fastFibonacci = _.memoize(function(n) {
return n < 2 ? n : fastFibonacci(n - 1) + fastFibonacci(n - 2);
});
```

I've not made up a jsperf page, but this runs way much faster.