Skip to content

Commit

Permalink
- Had to google how sqrt is actually calculated T_T .
Browse files Browse the repository at this point in the history
  • Loading branch information
PG-Momik committed Oct 20, 2024
1 parent b8375dc commit ec14601
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions _013_sqrt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @param {number} x
* @return {number}
*/
var mySqrt = function(x) {
if(x<2) return x;

let r = x;

while (r * r > x) {
r = Math.floor((r + x / r) / 2);
}

return r;
};

0 comments on commit ec14601

Please sign in to comment.