Skip to content

Instantly share code, notes, and snippets.

@jasonwaters
Created October 14, 2016 02:48
Show Gist options
  • Save jasonwaters/643fadd62f3dfc18680b6a87991f7094 to your computer and use it in GitHub Desktop.
Save jasonwaters/643fadd62f3dfc18680b6a87991f7094 to your computer and use it in GitHub Desktop.
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