Created
May 10, 2020 14:35
-
-
Save codingscode/52b2a72e8d2c61e9425fb316ec6270a7 to your computer and use it in GitHub Desktop.
Minimo Multiplo Comum com javascript
This file contains hidden or 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 delta = 0 | |
var mmc = 0 | |
var resposta = 0 | |
const minha_lista = [8, 6, 20] // | |
function maior(matriz) { | |
return matriz.reduce(function (a, b) { | |
return Math.max(a, b) | |
}) | |
} | |
function resto0(numero, matriz, p) { | |
if ((maior(matriz) + p) % numero == 0) { | |
return true | |
} | |
else { | |
return false | |
} | |
} | |
function achar_mmc(matriz, p) { | |
return (matriz).every((cada, indice) => { | |
return resto0(cada, matriz, p) | |
}) | |
} | |
function tentativas(matriz, p) { | |
while (achar_mmc(matriz, p) == false) { | |
mmc = maior(matriz) + p | |
p += 1 | |
} | |
return mmc | |
} | |
tentativas(minha_lista, delta) | |
resposta = mmc + 1 | |
console.log('maior elemento : ' + maior(minha_lista)) | |
console.log('mmc: ' + resposta) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment