Created
October 14, 2016 02:48
-
-
Save jasonwaters/643fadd62f3dfc18680b6a87991f7094 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
function findSqRt(target) { | |
var upper = target, | |
lower = 0, | |
square=0, | |
value=0; | |
while(Math.abs(target-square) >= 0.00000001) { | |
value = (upper + lower) /2; | |
square = value * value; | |
if(square > target) { | |
upper = value; | |
}else if(square < target) { | |
lower = value; | |
} | |
} | |
return value; | |
} | |
console.log(findSqRt(10)); | |
console.log(Math.sqrt(10)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment