Skip to content
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
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Create AnyBase #1534

wants to merge 10 commits into from

Conversation

imrahulkb
Copy link
Contributor

Open in Gitpod 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:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new JavaScript files are placed inside an existing directory.
  • All filenames should use the UpperCamelCase (PascalCase) style. There should be no spaces in filenames.
    Example:UserProfile.js is allowed but userprofile.js,Userprofile.js,user-Profile.js,userProfile.js are not
  • All new algorithms have a URL in their comments that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

Copy link
Collaborator

@appgurueu appgurueu left a 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 taking fromBase and toBase and returning a function(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 a stringifyInt(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.

@imrahulkb
Copy link
Contributor Author

I am facing errors due to style of the test file i have created, kindly guide me with this problem

@raklaptudirm
Copy link
Member

Since the tests passed I assume you have solved the style issue?

@imrahulkb
Copy link
Contributor Author

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants