feat(SquareRoot.js): Added TypeError

This commit is contained in:
Rak Laptudirm
2021-05-13 13:07:15 +05:30
parent a22c0486e7
commit 2c1052da8b

View File

@ -7,6 +7,10 @@
*/ */
function sqrt (num, precision = 10) { function sqrt (num, precision = 10) {
if (!Number.isFinite(num))
throw new TypeError(`Expected a number, received ${typeof num}`)
if (!Number.isFinite(precision))
throw new TypeError(`Expected a number, received ${typeof precision}`)
let sqrt = 1 let sqrt = 1
for (let i = 0; i < precision; i++) { for (let i = 0; i < precision; i++) {
sqrt -= (sqrt * sqrt - num) / (2 * sqrt) sqrt -= (sqrt * sqrt - num) / (2 * sqrt)