Skip to content

Add proper tests for binary search #987

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

Merged
merged 9 commits into from
Apr 21, 2022

Conversation

CarlosZoft
Copy link
Member

Welcome to the JavaScript community

Open in Gitpod know more

Describe your change:

  • Add an algorithm?
  • Add some test?

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 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

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.

How does this compare to the current implementation? From what I can see it's merely a less readable iterative version. If it showed better traits than the current one, you may replace it. But I don't see the merit of two largely similar iterative implementations.

@appgurueu appgurueu added the on hold Being discussed by the maintainers label Apr 19, 2022
@raklaptudirm
Copy link
Member

@appgurueu since it is being added as a separate implementation, I think we could add it. It is using some more js features, which could be wanted. What do you think?

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.

This PR may indeed be using more JS features (primarily ternaries) but in a wrong manner; they only make the code less readable (except probably for the last ternary). Currently I see only two very tiny advantages over the other impl., the simplification of the term for mid and moving the check if found out of the loop; I don't see much of a benefit from the exclusive low & high indices, which is a mere convention. On the other hand however there is rather unreadable code, bad comments and syntactic sugar where it doesn't belong.

The tiny improvements should just be changes to the current implementation.

@appgurueu appgurueu added feature Adds a new feature changes required This pull request needs changes labels Apr 20, 2022
@appgurueu
Copy link
Collaborator

At this point it's similar enough that you should just tidy up the existing implementation (adding proper jest tests) instead.

@appgurueu appgurueu removed the changes required This pull request needs changes label Apr 20, 2022
@CarlosZoft
Copy link
Member Author

I did this

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.

From a quick glance the tests look fine to me. Definitely a significant improvement. But please deduplicate the code; you can do something like funcs = {iterative: binarySearchIterative, recursive: binarySearchRecursive}; for (let name in funcs) runTests(name, funcs[name]) where runTests is a parameterized function that runs the tests (which are the same for both implementations).

@CarlosZoft
Copy link
Member Author

Nice vision, i will make this!

@CarlosZoft
Copy link
Member Author

CarlosZoft commented Apr 20, 2022

lgtm now, what you think?

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.

Thank you for your contribution. LGTM!

@appgurueu appgurueu changed the title feat: added alternative binary search Add proper tests for binary search Apr 20, 2022
@raklaptudirm raklaptudirm merged commit 298ab33 into TheAlgorithms:master Apr 21, 2022
@raklaptudirm raklaptudirm removed the on hold Being discussed by the maintainers label Apr 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Adds a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants