freeCodeCamp/guide/english/certifications/javascript-algorithms-and-d.../intermediate-algorithm-scri...
Bill Sourour f0eb384b10 Smallest Common Multiple – Optimized Advanced Solution (#19572)
* Optimized advanced solution

Made 2 minor improvement to the advanced solution:

1. The original advanced solution used `Math.max` and `Math.min` against the supplied array, this causes the values in the supplied array to be compared twice. If we use sort instead, the values are only compared once and we can target the max and min values using an index. This is more efficient.

2. The original solution caused `lcm(min, min + 1)` to be evaluated twice. By incrementing `min` the first time we run `lcm` we avoid this duplication and also by taking advantage of the prefix increment operator ++ in the while loop, we trim a line.

* Fixed extra spaces in code block

* Incorporated code feedback from #19572

Made the following changes to the advanced code solution:

- Converted helper functions to arrow function constants
- Simplified comments
- Used destructuring and `sort` for `min` and `max`

* Fixed spacing.
2018-10-18 10:08:45 -07:00
..
arguments-optional fix(guide): simplify directory structure 2018-10-16 21:32:40 +05:30
binary-agents fix(guide): simplify directory structure 2018-10-16 21:32:40 +05:30
convert-html-entities fix(guide): simplify directory structure 2018-10-16 21:32:40 +05:30
diff-two-arrays fix(guide): simplify directory structure 2018-10-16 21:32:40 +05:30
dna-pairing fix(guide): simplify directory structure 2018-10-16 21:32:40 +05:30
drop-it fix(guide): simplify directory structure 2018-10-16 21:32:40 +05:30
everything-be-true fix(guide): simplify directory structure 2018-10-16 21:32:40 +05:30
make-a-person fix(guide): simplify directory structure 2018-10-16 21:32:40 +05:30
map-the-debris fix(guide): simplify directory structure 2018-10-16 21:32:40 +05:30
missing-letters fix(guide): simplify directory structure 2018-10-16 21:32:40 +05:30
pig-latin fix(guide): simplify directory structure 2018-10-16 21:32:40 +05:30
search-and-replace fix(guide): simplify directory structure 2018-10-16 21:32:40 +05:30
seek-and-destroy fix(guide): simplify directory structure 2018-10-16 21:32:40 +05:30
smallest-common-multiple Smallest Common Multiple – Optimized Advanced Solution (#19572) 2018-10-18 10:08:45 -07:00
sorted-union fix(guide): simplify directory structure 2018-10-16 21:32:40 +05:30
spinal-tap-case fix(guide): simplify directory structure 2018-10-16 21:32:40 +05:30
steamroller fix(guide): simplify directory structure 2018-10-16 21:32:40 +05:30
sum-all-numbers-in-a-range fix(guide): simplify directory structure 2018-10-16 21:32:40 +05:30
sum-all-odd-fibonacci-numbers fix(guide): simplify directory structure 2018-10-16 21:32:40 +05:30
sum-all-primes fix(guide): simplify directory structure 2018-10-16 21:32:40 +05:30
wherefore-art-thou fix(guide): simplify directory structure 2018-10-16 21:32:40 +05:30
index.md fix(guide): simplify directory structure 2018-10-16 21:32:40 +05:30