-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Added isCompositeNumber.js #1063
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
13b7c24
Added Composite Number
tehliang 4d12b51
Updated isCompositeNumber
tehliang 3a330fc
Merge pull request #1 from tehliang/Test-1
tehliang ccc7ff7
Updated IsCompositeNumber 2
tehliang 9672cb5
Updated IsCompositeNumber.js
tehliang 42342ae
Merge pull request #3 from tehliang/Test-1
tehliang 205246e
Update IsCompositeNumber.js
tehliang 6fa1484
Merge pull request #4 from tehliang/Test-1
tehliang 5d68622
Create xd
riddlestar 0740b2c
Update 2
tehliang cc1a0dc
Merge pull request #5 from riddlestar/riddlestar-patch-1
tehliang df18ba2
Create Codecov
tehliang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Composite number: https://en.wikipedia.org/wiki/Composite_number | ||
* function isCompositeNumber | ||
* Check if a given number is a composite number or not? | ||
* isCompositeNumber(6) // returns true | ||
* isCompositeNumber(577) // returns false | ||
* isCompositeNumber(2024) // returns true | ||
* A composite number is a positive integer that is not prime. In other words, it has a positive divisor other than one or itself. | ||
* First few composite numbers are 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, ......... | ||
* Every integer greater than one is either a prime number or a composite number. | ||
* The number one is a unit – it is neither prime nor composite. | ||
*/ | ||
|
||
function isCompositeNumber (number) { | ||
let i = 1 | ||
let count = 0 | ||
while (number >= i) { | ||
tehliang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (number % i === 0) { | ||
count++ | ||
} | ||
i++ | ||
} | ||
if (count > 2) { | ||
return true | ||
} else { | ||
return false | ||
} | ||
} | ||
|
||
export { isCompositeNumber } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { isCompositeNumber } from '../IsCompositeNumber' | ||
|
||
describe('Testing isCompositeNumber function', () => { | ||
it('should return true if the number is composite number', () => { | ||
expect(isCompositeNumber(6)).toBe(true) | ||
}) | ||
|
||
it('should return false if the number is not composite number', () => { | ||
expect(isCompositeNumber(577)).toBe(false) | ||
}) | ||
|
||
it('should return true if the number is composite number', () => { | ||
expect(isCompositeNumber(2024)).toBe(true) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.