Skip to content

Conversation

@Askanders
Copy link
Contributor

@Askanders 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}.
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.
Copy link
Member

@ruppysuppy ruppysuppy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@ruppysuppy
Copy link
Member

@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

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 itsvinayak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

everything seems fine
thank you for PR @Askanders

@itsvinayak
Copy link
Member

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants