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

Update BinarySearch.js #209

Merged
merged 4 commits into from Jun 28, 2020
Merged

Update BinarySearch.js #209

merged 4 commits into from Jun 28, 2020

Conversation

@Askanders
Copy link
Contributor

Askanders commented Jun 27, 2020

The old algorithm didn't work, I believe for two main reasons:
1 - Number.MAX_VALUE is not a valid array index as it is used to represent the highest possible value in javascript (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE);

2 - splice() is not a pure function, every time it is called it has the side effect of modifying the original array (https://www.w3schools.com/jsref/jsref_splice.asp) ;

So I rewrote the algorithm, it now returns an index ( -1 if not found ) and it works both on numbers and on strings.

Welcome to JavaScript community

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 its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.
Askanders added 4 commits Jun 27, 2020
The old algorithm didn't work, I believe for two main reasons:
1 -  Number.MAX_VALUE is not a valid array index as it is used to represent the highest possible value in javascript (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE);

2 - splice() is not a pure function, every time it is called it has the side effect of modifying the original array (https://www.w3schools.com/jsref/jsref_splice.asp) ;

So I rewrote the algorithm, it now returns an index ( -1 if not found ) and it works both on numbers and on strings.
Style change
Style change
Copy link
Contributor

ruppysuppy left a comment

Everything else looks fine to me, still I would appriciate if @itsvinayak would review it once

@ruppysuppy
Copy link
Contributor

ruppysuppy commented Jun 27, 2020

@Askanders, you can run $ standard MyFile.js as stated in CONTRIBUTING.md to format the file instead of formatting it manually

@Askanders
Copy link
Contributor Author

Askanders commented Jun 27, 2020

Yes, thank you @ruppysuppy. I have a lot of configuration to do so I haven't installed the package yet, but I'll definitely do it in the future.

Copy link
Member

itsvinayak left a comment

everything seems fine
thank you for PR @Askanders

@itsvinayak
Copy link
Member

itsvinayak commented Jun 28, 2020

Everything else looks fine to me, still I would appriciate if @itsvinayak would review it once

sure and thanks for helping @ruppysuppy

@itsvinayak itsvinayak merged commit ef5566f into TheAlgorithms:master Jun 28, 2020
2 checks passed
2 checks passed
build (14.x)
Details
LGTM analysis: JavaScript No new or fixed alerts
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.