-
-
Save danielramosbh74/eb357577ead77765d90fb2fe103408be to your computer and use it in GitHub Desktop.
Calculo de Mínimo Múltiplo Comum em Javascript / Calculation of Common Minimum in Javascript
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
function divisibleAll(numbers, multiple) { | |
for (let i = 0; i < numbers.length; i++) { | |
if (multiple % numbers[i] !== 0) { | |
return false; | |
} | |
} | |
return true; | |
} | |
function mmc(numbers) { | |
numbers.sort((a, b) => { | |
if (a > b) { | |
return -1; | |
} | |
if (a < b) { | |
return 1; | |
} | |
return 0; | |
}); | |
numbers = Array.from(new Set(numbers)); | |
var greather = numbers.shift(); | |
var i = 1; | |
while (true) { | |
let multiple = greather * i; | |
if (divisibleAll(numbers, multiple)) { | |
return multiple; | |
} | |
i++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment