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
Create AnyBase #1534
Open
imrahulkb
wants to merge
10
commits into
TheAlgorithms:master
Choose a base branch
from
imrahulkb:patch-6
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Create AnyBase #1534
Conversation
This file contains 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
appgurueu
requested changes
Oct 17, 2023
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.
- Why a class? A single function with
fromBase
,toBase
,str
parameters would work as well. If anything, this should be a function takingfromBase
andtoBase
and returning afunction(str)
that does the conversion (a "converter" if you will). - It seems to me a cleaner design would be a
parseInt(str, base)
function plus astringifyInt(str, base)
function, somewhat similar to how JS does it. - Needs tests and docs (JSDoc comments).
- This likely obsoletes a few existing conversions. These should be removed.
convert object oriented code to procedure oriented code
Added tests for convert base
I am facing errors due to style of the test file i have created, kindly guide me with this problem |
Since the tests passed I assume you have solved the style issue? |
Yes, I have solved the issue in the latest commit. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
know more
Describe your change:
This is a method for converting numbers from one base to another when both bases are in the range 2 to 10.
Because the procedure employed here is more broad, it requires both bases when generating the object. The convert function is used to convert numbers from one base to another.
Internally, there is a micro convert function that will work intermediately because the core algorithm requires one of the bases to be 10, thus the number will be converted to base 10 first and then to the appropriate base.
Unwanted interference can be avoided by using if else, as in if one of the bases is 10.
Checklist:
Example:
UserProfile.js
is allowed butuserprofile.js
,Userprofile.js
,user-Profile.js
,userProfile.js
are notFixes: #{$ISSUE_NO}
.