Skip to content

Instantly share code, notes, and snippets.

@bencoveney
Created June 14, 2014 15:24
Show Gist options
  • Save bencoveney/c1eb0e04879bafde4c70 to your computer and use it in GitHub Desktop.
Save bencoveney/c1eb0e04879bafde4c70 to your computer and use it in GitHub Desktop.
Smallest Multiple
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