Created
December 5, 2015 10:13
-
-
Save clive-bunting/4aa348dabaff95678425 to your computer and use it in GitHub Desktop.
Bonfire: Smallest Common Multiple
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
| // Bonfire: Smallest Common Multiple | |
| // Author: @clive-bunting | |
| // Challenge: http://www.freecodecamp.com/challenges/bonfire-smallest-common-multiple# | |
| // Learn to Code at Free Code Camp (www.freecodecamp.com) | |
| function smallestCommons(arr) { | |
| var lbound = Math.min(arr[0], arr[1]); | |
| var ubound = Math.max(arr[0], arr[1]); | |
| var multiple = 0; | |
| var multipleFound = false; | |
| var step = ubound * (ubound - 1); | |
| do { | |
| multiple += step; | |
| console.log(multiple); | |
| multipleFound = true; | |
| for (var i = lbound; i <= ubound; i++) { | |
| if (multiple % i !== 0) { | |
| multipleFound = false; | |
| } | |
| } | |
| } while (!multipleFound); | |
| return multiple; | |
| } | |
| smallestCommons([1,5]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment