Created
October 2, 2018 06:03
-
-
Save jepras/e27f61c0a4f18d5b5d02dc1e5598d31b to your computer and use it in GitHub Desktop.
This file contains 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
// Stolen from fCC solutions - could not figure it out | |
function smallestCommons(arr) { | |
// Sort array from greater to lowest | |
// This line of code was from Adam Doyle (http://github.com/Adoyle2014) | |
arr.sort(function(a, b) { | |
return b - a; | |
}); | |
// Create new array and add all values from greater to smaller from the | |
// original array. | |
var newArr = []; | |
for (var i = arr[0]; i >= arr[1]; i--) { | |
newArr.push(i); | |
} | |
// Variables needed declared outside the loops. | |
var quot = 0; | |
var loop = 1; | |
var n; | |
// Run code while n is not the same as the array length. | |
do { | |
quot = newArr[0] * loop * newArr[1]; | |
for (n = 2; n < newArr.length; n++) { | |
if (quot % newArr[n] !== 0) { | |
break; | |
} | |
} | |
loop++; | |
} while (n !== newArr.length); | |
return quot; | |
} | |
smallestCommons([1,5]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment