Skip to content

Instantly share code, notes, and snippets.

@Quby
Created September 24, 2011 15:08
Show Gist options
  • Select an option

  • Save Quby/1239433 to your computer and use it in GitHub Desktop.

Select an option

Save Quby/1239433 to your computer and use it in GitHub Desktop.
SICP in javascript
var factorial = (function () {
"use strict";
function fact (product, counter, x) {
return counter > x ? product : fact(counter * product, counter + 1, x);
}
return function (x) {
return fact(1, 1, x);
};
})();
var sqrt = (function () {
"use strict";
function sqrt (n, x, p) {
return Math.abs(x*x - n) < p ? x : sqrt(n, (n/x + x) / 2, p);
}
return function (n) {
return sqrt(n, 1, 0.001);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment