Skip to content

Instantly share code, notes, and snippets.

@clive-bunting
Created December 5, 2015 10:13
Show Gist options
  • Select an option

  • Save clive-bunting/4aa348dabaff95678425 to your computer and use it in GitHub Desktop.

Select an option

Save clive-bunting/4aa348dabaff95678425 to your computer and use it in GitHub Desktop.
Bonfire: Smallest Common Multiple
// 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