Created
November 9, 2013 04:07
-
-
Save animatedlew/7381483 to your computer and use it in GitHub Desktop.
Revisions
-
animatedlew created this gist
Nov 9, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ var sqrt = function(x) { var isGoodEnough = function(guess) { return Math.abs(guess * guess - x) / x < 0.001; }; var improve = function(guess) { return (guess + x / guess) / 2; }; var sqrIter = function(guess) { return (isGoodEnough(guess)) ? guess : sqrIter(improve(guess)) }; return sqrIter(1.0); }; console.log( Math.sqrt(1000), sqrt(1000) );