Skip to content

Commit 92b8b46

Browse files
add type checking
1 parent c67b0e9 commit 92b8b46

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Maths/GetGCD.js renamed to Maths/GetEuclidGCD.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Problem statement and Explanation : https://en.wikipedia.org/wiki/Greatest_common_divisor
2+
Problem statement and Explanation : https://en.wikipedia.org/wiki/Euclidean_algorithm
33
44
In this method, we have followed the iterative approach to first
55
find a minimum of both numbers and go to the next step.
@@ -12,6 +12,10 @@
1212
* @returns return a `gcd` value of both number.
1313
*/
1414
const getGcd = (arg1, arg2) => {
15+
// firstly, check that input is a number or not.
16+
if (typeof arg1 !== 'number' || typeof arg2 !== 'number') {
17+
return new TypeError('Argument is not a number.')
18+
}
1519
// Find a minimum of both numbers.
1620
let less = arg1 > arg2 ? arg2 : arg1
1721
// Iterate the number and find the gcd of the number using the above explanation.

Maths/ReverseNumber.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
* @returns `Number` n reverse in reverse.
99
*/
1010
const ReverseNumber = (number) => {
11+
// firstly, check that input is a number or not.
12+
if (typeof number !== 'number') {
13+
return new TypeError('Argument is not a number.')
14+
}
1115
// A variable for storing the reversed number.
1216
let reverseNumber = 0
1317
// Iterate the process until getting the number is 0.

0 commit comments

Comments
 (0)