Skip to content

Commit d1964af

Browse files
committed
Add Babylonian Square Root for Javascript
1 parent 0027b19 commit d1964af

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function squareRoot(num) {
2+
const e = 0.00000001;
3+
let x = num;
4+
let y = 1;
5+
6+
while(x - y > e) {
7+
x = (x + y) / 2;
8+
y = num / x;
9+
}
10+
11+
return x;
12+
}
13+
14+
console.log(squareRoot(5));

0 commit comments

Comments
 (0)