{{{
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);
w
I have a different approach to a similar problem:
{{{
function fib(n) {
fib = function (n) {
fib.calls++;
if (fib.cache[n] === undefined) {
fib.cache[n] = fib(n - 1) + fib(n - 2);
}
return fib.cache[n];
}
fib.calls = 0;
fib.cache = [0, 1];
return fib(n);
}
function
On 21 June 2011 18:48, Dmitry A. Soshnikov wrote:
> On 21.06.2011 2:22, Nick Morgan wrote:
>>
>> Hi all
>>
>> I've been messing about with streams in JavaScript, trying to
>> implement some of the code from section 3.5
>> (http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-24.html#%_sec_3.5)
>>
On 21.06.2011 2:22, Nick Morgan wrote:
Hi all
I've been messing about with streams in JavaScript, trying to
implement some of the code from section 3.5
(http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-24.html#%_sec_3.5)
of SICP.
The book which I recommend to read for _every_ programmer.
Hi all
I've been messing about with streams in JavaScript, trying to
implement some of the code from section 3.5
(http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-24.html#%_sec_3.5)
of SICP.
Here's a fiddle showing the Sieve of Eratosthenes, displaying each
prime as it is found. http://jsfidd