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

feat : added reverse number method #1386

Closed
wants to merge 1 commit into from
Closed

feat : added reverse number method #1386

wants to merge 1 commit into from

Conversation

dev-madhurendra
Copy link
Contributor

@dev-madhurendra dev-madhurendra commented Oct 1, 2023

Open in Gitpod know more

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

@raklaptudirm
Copy link
Member

@appgurueu I think this algorithm falls in the trivial category that we discussed in the discord previously, so I don't think it will be a good addition to the repo. What is your opinion?

@appgurueu
Copy link
Collaborator

appgurueu commented Oct 2, 2023

Well it is pretty trivial, but I think it is useful to demonstrate the split-transform-join pattern for working around the immutability of strings in JavaScript.

Arguably this shouldn't be called "reverse number" though - it isn't really specific to numbers - but it should be "reverse string" which we already have (but not using JS's reverse, which would be more concise). I missed this in my review.

@dev-madhurendra please just shorten the existing linear time string reversal code to a one-liner.

@dev-madhurendra
Copy link
Contributor Author

Well it is pretty trivial, but I think it is useful to demonstrate the split-transform-join pattern for working around the immutability of strings in JavaScript.

Arguably this shouldn't be called "reverse number" though - it isn't really specific to numbers - but it should be "reverse string" which we already have (but not using JS's reverse, which would be more concise). I missed this in my review.

@dev-madhurendra please just shorten the existing linear time string reversal code to a one-liner.

@appgurueu It is already one linear

Well it is pretty trivial, but I think it is useful to demonstrate the split-transform-join pattern for working around the immutability of strings in JavaScript.

Arguably this shouldn't be called "reverse number" though - it isn't really specific to numbers - but it should be "reverse string" which we already have (but not using JS's reverse, which would be more concise). I missed this in my review.

@dev-madhurendra please just shorten the existing linear time string reversal code to a one-liner.

@appgurueu I think it is already one linear.

@appgurueu
Copy link
Collaborator

appgurueu commented Oct 2, 2023

What I'm saying is that this function should just be a string-, not a number reversal function. If someone wants to apply that to a number, they can do the conversions themselves. However, we already have that, so you should just clean up / simplify the existing code to a one-liner:
It is already linear-time, but it is not a one-liner: It is needlessly verbose as it manually does the array reversal rather than using JS's reverse built-in. It should be just str.split('').reverse().join('') (or [...str].reverse().join('')).

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