-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Add pronic number implementation #1023
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
Merged
raklaptudirm
merged 13 commits into
TheAlgorithms:master
from
itsAkshayDubey:add-pronic-number-implementation
May 25, 2022
Merged
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2157d10
feat: Add pronic number implementation
itsAkshayDubey 4314cc7
Add test to Math
itsAkshayDubey c607982
Minor fixes
itsAkshayDubey e1ff6cc
Minor style fixes
itsAkshayDubey 512a40a
refactor: Store square root in a variable
itsAkshayDubey 951b584
Minor refactoring
itsAkshayDubey a077a87
fix: Change pronic number check logic
itsAkshayDubey dd9093e
Minor style fixes
itsAkshayDubey 363ed98
fix: Update pronic number check boolean equation
itsAkshayDubey a5c4131
refactor: Change pronic number check condition
itsAkshayDubey 308cd44
refactor: Add tests to Math
itsAkshayDubey 9969015
Minor style fixes
itsAkshayDubey 8eeb2d2
refactor: Change unit test logic
itsAkshayDubey 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,37 @@ | ||
/* | ||
* Author: Akshay Dubey (https://github.com/itsAkshayDubey) | ||
* Pronic Number: https://en.wikipedia.org/wiki/Pronic_number | ||
* function to check if number is pronic. | ||
* return true if number is pronic. | ||
* else false | ||
*/ | ||
|
||
/** | ||
* @function isPronic | ||
* @description -> Checking if number is pronic using product of two consecutive numbers | ||
* If number is a product of two consecutive numbers, then it is pronic | ||
* therefore, the function will return true | ||
* | ||
* If number is not a product of two consecutive numbers, then it is not pronic | ||
* therefore, the function will return false | ||
* @param {number} number | ||
* @returns {boolean} | ||
*/ | ||
|
||
function isPronic (number) { | ||
if (number % 2 === 1) { | ||
return false | ||
} | ||
|
||
for (let i = 0; i <= Math.sqrt(number); i++) { | ||
itsAkshayDubey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Checking Pronic Number | ||
// by multiplying consecutive | ||
// numbers | ||
if (number === i * (i + 1)) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
export { isPronic } |
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,18 @@ | ||
import { isPronic } from '../IsPronic' | ||
|
||
describe('Testing isPronic function', () => { | ||
raklaptudirm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
it('should return if the number is pronic or not for even number', () => { | ||
const isPronicNumber = isPronic(2) | ||
expect(isPronicNumber).toBe(true) | ||
}) | ||
|
||
it('should return if the number is pronic or not for even number', () => { | ||
const isPronicNumber = isPronic(4) | ||
itsAkshayDubey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(isPronicNumber).toBe(false) | ||
}) | ||
|
||
it('should return false for odd number', () => { | ||
const isPronicNumber = isPronic(7) | ||
expect(isPronicNumber).toBe(false) | ||
}) | ||
}) |
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.
Uh oh!
There was an error while loading. Please reload this page.