Created
May 22, 2012 19:05
-
-
Save wyattdanger/2770984 to your computer and use it in GitHub Desktop.
This file contains 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 characters
squareRoot = ( num ) -> | |
square = ( x ) -> x * x | |
avg = ( x, y ) -> (x + y) / 2 | |
goodEnough = ( x ) -> Math.abs( square( x ) - num ) < 0.01 | |
improveGuess = ( x ) -> avg( x, num/x ) | |
iter = ( guess ) -> | |
return guess if goodEnough guess | |
iter improveGuess guess | |
iter 1.0 | |
alert squareRoot 101 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment