{{{
function fib(n) {
  fib = function (n) {
    if (fib.cache[n] === undefined) {
      fib.cache[n] = fib(n - 1) + fib(n - 2);
    }
    return fib.cache[n];
  }
  fib.cache = [0, 1];
  fib.next = function () {
    return fib(fib.cache.length);
  }
  return fib(n);
}

(function(n) {
  fib(0);
  while (n--) {
    console.log(fib.next());
  }
}(10));
}}}

Output:
{{{
1
2
3
5
8
13
21
34
55
89
}}

-- 
Poetro

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to