Skip to content
  • Sponsor TheAlgorithms/TypeScript

  • Notifications You must be signed in to change notification settings
  • Fork 437
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b347325

Browse files
committedSep 25, 2024
added function to check co-primes
1 parent 44127b2 commit b347325

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
 

‎maths/are_coprime.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { greatestCommonFactor } from "./greatest_common_factor"
2+
3+
export const areCoprime = (a: number, b: number): boolean =>{
4+
5+
if(greatestCommonFactor([a,b]) === 1){
6+
return true;
7+
}
8+
return false;
9+
}

‎maths/test/are_coprime.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { areCoprime } from "../are_coprime";
2+
3+
describe('areCoprime', ()=> {
4+
it('should return false when numbers are not coprime', () => {
5+
const value = areCoprime(2,4)
6+
expect(value).toBe(false)
7+
})
8+
9+
it('should return true when numbers are coprime', () => {
10+
const value = areCoprime(2,3)
11+
expect(value).toBe(true)
12+
})
13+
})

0 commit comments

Comments
 (0)
Please sign in to comment.