Skip to content

Combined Min Heap and Max Heap classes #1494

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

Conversation

ROHAN13498
Copy link
Contributor

Open in Gitpod know more

Deduplicated the code of Minheap and Maxheap and used a single binary heap class.

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

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.

Looks mostly fine. Some points:

  • The tests are pretty much duplicated. IMO it would be fine to test just min or max heap, then test that the comparator is being used at all with a small example of the opposite ordering. But I'm not terribly opposed to this; it needs to be tested one way or another.
  • You got rid of explanatory comments. Please readd some. At the very least, please add JSDoc comments to public methods, and mark "private" methods (like bubbleUp, sinkDown and swap) as such using the # prefix.

@ROHAN13498
Copy link
Contributor Author

Yeah!You are right.I will work on that and get back to you.

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.

As said, bubbleUp / sinkDown / swap should all be private (not just documented as private, but actually private by prefixing them with #).

@ROHAN13498 ROHAN13498 requested a review from appgurueu October 9, 2023 17:29
I assume the @Class tag is for classes implemented via constructor functions, not using ES6 class syntax
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.

Though you have some redundant tags there (e.g. there's no need for @private for #methods, no need to document the heap member (which btw should maybe also be private)).

@ROHAN13498
Copy link
Contributor Author

I did this under hactober fest will it be counted?

@appgurueu
Copy link
Collaborator

I did this under hactober fest will it be counted?

Yes, it should be. From the Hacktoberfest website:

Maintainers accept PR/MRs by merging them, labeling them “hacktoberfest-accepted,” or giving them an overall approving review.

The last point is what I effectively just did :)

@ROHAN13498
Copy link
Contributor Author

The last point is what I effectively just did :)

Thanks a lot @appgurueu

@appgurueu
Copy link
Collaborator

The last point is what I effectively just did :)

Thanks a lot @appgurueu

np, thank you for your contribution :) it's important that every now and then someone takes the time to refactor something

@raklaptudirm raklaptudirm merged commit 13161bd into TheAlgorithms:master Oct 10, 2023
@ROHAN13498
Copy link
Contributor Author

ROHAN13498 commented Oct 10, 2023

@appgurueu are there any more issues that you would suggest me to work on?

@appgurueu
Copy link
Collaborator

appgurueu commented Oct 10, 2023

@appgurueu are there any more issues that you would suggest me to work on?

No, but if you see other places where code is duplicated (or that otherwise have low code quality and warrant a refactor - plenty of such cases in this repo), or want to add an interesting algorithm, feel free to open a PR :)

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.

3 participants