-
-
Notifications
You must be signed in to change notification settings - Fork 250
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: add next power of 2 algorithm #193
base: master
Are you sure you want to change the base?
Conversation
Please merge it under hacktoberfest |
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.
Otherwise looks fine.
*/ | ||
|
||
export const findNextPowerOf2 = (n: number): number => { | ||
n !== 0 ? n-- : n; |
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.
This should be written more readably as if (n !== 0) n--
.
|
||
describe("find next power of two", () => { | ||
test.each([ | ||
[0, 2], |
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.
This seems odd to me. Shouldn't the next power of two be 2⁰ = 1?
This PR add an implementation to find the next power of 2 using bit manipulation