repl.it
@mcuringa/

Newton Sqare Root

ES6

No description

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function sqrt(n) {
  let approx = n/2;   // Start with some or other guess at the answer
  let better = (approx + n/approx)/2;
  while (Math.abs(approx - better) > .001) {
    approx = better;
    better = (approx + n/approx)/2.0;
  }
  return better;
}

// Test cases
console.log(sqrt(25));
console.log(sqrt(49));
console.log(sqrt(81));

"fpp".
Babel Compiler v6.4.4 Copyright (c) 2014-2015 Sebastian McKenzie
?