Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
Show file tree
Hide file tree
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 May 25, 2022
4314cc7
Add test to Math
itsAkshayDubey May 25, 2022
c607982
Minor fixes
itsAkshayDubey May 25, 2022
e1ff6cc
Minor style fixes
itsAkshayDubey May 25, 2022
512a40a
refactor: Store square root in a variable
itsAkshayDubey May 25, 2022
951b584
Minor refactoring
itsAkshayDubey May 25, 2022
a077a87
fix: Change pronic number check logic
itsAkshayDubey May 25, 2022
dd9093e
Minor style fixes
itsAkshayDubey May 25, 2022
363ed98
fix: Update pronic number check boolean equation
itsAkshayDubey May 25, 2022
a5c4131
refactor: Change pronic number check condition
itsAkshayDubey May 25, 2022
308cd44
refactor: Add tests to Math
itsAkshayDubey May 25, 2022
9969015
Minor style fixes
itsAkshayDubey May 25, 2022
8eeb2d2
refactor: Change unit test logic
itsAkshayDubey May 25, 2022
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
37 changes: 37 additions & 0 deletions Maths/IsPronic.js
View file Open in desktop
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++) {
// Checking Pronic Number
// by multiplying consecutive
// numbers
if (number === i * (i + 1)) {
return true
}
}
return false
}

export { isPronic }
18 changes: 18 additions & 0 deletions Maths/test/IsPronic.test.js
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { isPronic } from '../IsPronic'

describe('Testing isPronic function', () => {
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)
expect(isPronicNumber).toBe(false)
})

it('should return false for odd number', () => {
const isPronicNumber = isPronic(7)
expect(isPronicNumber).toBe(false)
})
})

AltStyle によって変換されたページ (->オリジナル) /