FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Update sumAll-solution.js swap algorithm to standard method by cats256 · Pull Request #368 · TheOdinProject/javascript-exercises · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
7 changes: 6 additions & 1 deletion 05_sumAll/solution/sumAll-solution.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ const sumAll = function (min, max) {
min = max;
max = temp;
}

// An alternative way to swap the values of min and max like above is to use the array destructuring syntax.
// Here's an optional article on it: https://www.freecodecamp.org/news/array-destructuring-in-es6-30e398f21d10/
// if (min > max) [min, max] = [max, min];

let sum = 0;
for (let i = min; i < max + 1; i++) {
for (let i = min; i <= max; i++) {
sum += i;
}
return sum;
Expand Down

Back | FazBrowse Home | New Git URL