-
-
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
Add pronic number implementation #1023
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Format your code using standard.js
. Read the CONTRIBUTING.md
before contributing.
Reduced time complexity from O(sqrt(n)) to O(1)
The current implementation is very odd: (1) you don't need to check whether numbers are odd if your equation works (2) your equation is unnecessarily convoluted. |
Refactored it, have a look. |
Why use if (number === 0) return true
const sqrt = Math.sqrt(number)
return sqrt % 1 !== 0 && Math.ceil(sqrt) * Math.floor(sqrt) === number Please extend the tests to check all example numbers listed on https://oeis.org/A002378 - it's easy to mess up some edge cases. Also check that all other numbers in the range aren't false positives. |
Added, have a look. |
Describe your change:
Checklist:
Example:
UserProfile.js
is allowed butuserprofile.js
,Userprofile.js
,user-Profile.js
,userProfile.js
are notFixes: #{$ISSUE_NO}
.