Created
June 14, 2014 15:24
-
-
Save bencoveney/c1eb0e04879bafde4c70 to your computer and use it in GitHub Desktop.
Smallest Multiple
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
var iterator = 1; | |
var isMultiple = function(number) { | |
// divide the number by every number between 1 & 20 | |
for(var i = 1; i <= 20; i++) | |
{ | |
if(number % i != 0) | |
{ | |
// If the number wasn't divisible then we know it can't be a correct answer | |
return false; | |
} | |
} | |
return true; | |
} | |
// Test numbers until a valid value is found | |
while(!isMultiple(iterator)) | |
{ | |
iterator++; | |
} | |
console.log(iterator + " is the smallest multiple"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment