Skip to content

Commit c0a3fa6

Browse files
authored
Merge pull request #641 from KenjiroAI/babylonian-square-root-javascript
Add Babylonian Square Root for Javascript
2 parents c57b598 + d1964af commit c0a3fa6

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)