diff --git a/Javascript/Numbers/greatesCommonDivisor.js b/Javascript/Numbers/greatesCommonDivisor.js new file mode 100644 index 0000000..fde6e58 --- /dev/null +++ b/Javascript/Numbers/greatesCommonDivisor.js @@ -0,0 +1,10 @@ +// gdc method returns the greatest common divisor between two numbers +const gcd = (a, b) => { + // firstly, check that input is a number or not. + if (typeof a !== 'number' || typeof b !== 'number') { + return 'invalid argument, not a number.' + } + return b === 0 ? a : gcd(b, a % b) +} + +console.log(gcd(10, 15))