Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2c1052d

Browse files
committed
feat(SquareRoot.js): Added TypeError
1 parent a22c048 commit 2c1052d

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

Maths/SquareRoot.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
*/
88

99
function sqrt (num, precision = 10) {
10+
if (!Number.isFinite(num))
11+
throw new TypeError(`Expected a number, received ${typeof num}`)
12+
if (!Number.isFinite(precision))
13+
throw new TypeError(`Expected a number, received ${typeof precision}`)
1014
let sqrt = 1
1115
for (let i = 0; i < precision; i++) {
1216
sqrt -= (sqrt * sqrt - num) / (2 * sqrt)

0 commit comments

Comments
 (0)