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 sumAll-solution.js swap algorithm to standard method #368

Merged
merged 4 commits into from
Jul 29, 2023

Conversation

cats256
Copy link
Contributor

@cats256 cats256 commented Jul 4, 2023

Because

I believe this way of swapping the values between variables in JavaScript is better for learners to know about since it is more common and reinforces understanding on array destructuring

This PR

Change the swapping algorithm to the standard way of swapping in JavaScript using array restructuring. Edit: Change for loop condition as well to the standard way

Pull Request Requirements

  • The title of this PR follows the location of change: brief description of change format, e.g. 01_helloWorld: Update test cases
  • The Because section summarizes the reason for this PR
  • The This PR section has a bullet point list describing the changes in this PR
  • If this PR addresses an open issue, it is linked in the Issue section
  • If this PR includes changes that needs to be updated on the solutions branch, I have created another PR (and linked it to this PR).

Change the swapping algorithm to the standard way of swapping using array restructuring.
@cats256 cats256 changed the title Update sumAll-solution.js Update sumAll-solution.js to standard method Jul 4, 2023
@cats256 cats256 changed the title Update sumAll-solution.js to standard method Update sumAll-solution.js swap algorithm to standard method Jul 4, 2023
Comment on lines 4 to 5
if (min > max) {
const temp = min;
min = max;
max = temp;
}
if (min > max) [min, max] = [max, min];

Copy link
Contributor

Choose a reason for hiding this comment

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

Not entirely sure if we should use this as the TOP solution, just because I don't believe it's something introduced to users at the point they're asked to do this exercise (believe it's the lesson they're first introduced to arrays).

Maybe we could add a comment that shows this method as an alternative.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@thatblindgeye thatblindgeye merged commit cdba6da into TheOdinProject:main Jul 29, 2023
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.

None yet

2 participants