Skip to content

Feat(maths): add check co-prime function #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
added function to check co-primes
  • Loading branch information
Ambarish-2002 committed Sep 25, 2024
commit b347325bacacfc1f89de24f9035d8ee954f59d94
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){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just export const areCoprime = (a: number, b: number): boolean => 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)
})
})