Skip to content
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

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 18 additions & 0 deletions maths/are_coprime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @function areCoprime
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @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){
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)
})
})
Loading