diff --git a/maths/are_coprime.ts b/maths/are_coprime.ts new file mode 100644 index 00000000..98f37f86 --- /dev/null +++ b/maths/are_coprime.ts @@ -0,0 +1,18 @@ +/** + * @function areCoprime + * @description Checks if two given numbers are co-prime or not + * @param {a} number - a numeric input value + * @param {a} number - a numeric input value + * @example areCoprime(2,4) = false + * @example areCoprime(2,3) = true + */ + +import { greatestCommonFactor } from "./greatest_common_factor" + +export const areCoprime = (a: number, b: number): boolean =>{ + + if(greatestCommonFactor([a,b]) === 1){ + return true; + } + return false; +} \ No newline at end of file diff --git a/maths/test/are_coprime.test.ts b/maths/test/are_coprime.test.ts new file mode 100644 index 00000000..bcfce77e --- /dev/null +++ b/maths/test/are_coprime.test.ts @@ -0,0 +1,13 @@ +import { areCoprime } from "../are_coprime"; + +describe('areCoprime', ()=> { + it('should return false when numbers are not coprime', () => { + const value = areCoprime(2,4) + expect(value).toBe(false) + }) + + it('should return true when numbers are coprime', () => { + const value = areCoprime(2,3) + expect(value).toBe(true) + }) +}) \ No newline at end of file
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: