Skip to content

Commit 09ce0c7

Browse files
change the GetGCD method to GetEuclidGCD method
1 parent 92b8b46 commit 09ce0c7

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Maths/GetEuclidGCD.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,27 @@
66
*/
77

88
/**
9-
* GetGCD return the gcd of two numbers.
9+
* GetEuclidGCD return the gcd of two numbers using Euclidean algorithm.
1010
* @param {Number} arg1 first argument for gcd
1111
* @param {Number} arg2 second argument for gcd
1212
* @returns return a `gcd` value of both number.
1313
*/
14-
const getGcd = (arg1, arg2) => {
14+
const GetEuclidGCD = (arg1, arg2) => {
1515
// firstly, check that input is a number or not.
1616
if (typeof arg1 !== 'number' || typeof arg2 !== 'number') {
1717
return new TypeError('Argument is not a number.')
1818
}
19+
// check that the input number is not a negative value.
20+
if (arg1 < 1 || arg2 < 1) {
21+
return new TypeError('Argument is a negative number.')
22+
}
1923
// Find a minimum of both numbers.
2024
let less = arg1 > arg2 ? arg2 : arg1
2125
// Iterate the number and find the gcd of the number using the above explanation.
2226
for (less; less >= 2; less--) {
2327
if ((arg1 % less === 0) && (arg2 % less === 0)) return (less)
2428
}
25-
2629
return (less)
2730
}
2831

29-
module.exports = getGcd
32+
module.exports = GetEuclidGCD

0 commit comments

Comments
 (0)