Skip to content

Commit

Permalink
added function to check co-primes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ambarish-2002 committed Sep 25, 2024
1 parent 44127b2 commit b347325
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions maths/are_coprime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { greatestCommonFactor } from "./greatest_common_factor"

export const areCoprime = (a: number, b: number): boolean =>{

if(greatestCommonFactor([a,b]) === 1){
return true;
}
return false;
}
13 changes: 13 additions & 0 deletions maths/test/are_coprime.test.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})

0 comments on commit b347325

Please sign in to comment.