Skip to content

Instantly share code, notes, and snippets.

View agustin107's full-sized avatar
🇦🇷
Working on a better versions of myself 💪🏽

Agustin N. R. Ramirez agustin107

🇦🇷
Working on a better versions of myself 💪🏽
View GitHub Profile
@joelpt
joelpt / squirt.js
Created October 2, 2012 23:41
Manually calculate the square root of a number with Javascript
// The Babylonian Method
// http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method
// @param n - the number to compute the square root of
// @param g - the best guess so far (can omit from initial call)
function squirt(n, g) {
if (!g) {
// Take an initial guess at the square root
g = n / 2.0;
}
var d = n / g; // Divide our guess into the number