Skip to content

Instantly share code, notes, and snippets.

@sghall
Created January 18, 2017 07:22
Show Gist options
  • Save sghall/6ced6002e2fa3e442c08691c8d03142d to your computer and use it in GitHub Desktop.
Save sghall/6ced6002e2fa3e442c08691c8d03142d to your computer and use it in GitHub Desktop.
Manual Square Root in JavaScript
function sqrt(num, guess) {
guess = guess || num / 3;
if (Math.abs(num - guess * guess) < 5e-15) {
return guess;
} else {
return sqrt(num, (num / guess + guess) / 2);
}
};
console.log(sqrt(25))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment