Last active
February 3, 2023 21:33
-
-
Save luisangelorjr/ed56afec8665af1659fbcafe1b5c2033 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
<html> | |
<script> | |
function somaMultiplos3ou5(numero) { | |
let multiplos3 = []; | |
let multiplos5 = []; | |
let soma = 0; | |
let resultado = 0 | |
for (let index = 1; resultado < numero; index++) { | |
resultado = 3 * index; | |
if (resultado < numero) { | |
multiplos3.push(resultado); | |
} | |
} | |
resultado = 0; | |
for (let index = 1; resultado < numero; index++) { | |
resultado = 5 * index; | |
if (resultado < numero) { | |
multiplos5.push(resultado); | |
} | |
} | |
for (const element of multiplos3) { | |
let comparadorMultiplo3 = element; | |
for (let indexmultiplos5 = 0; indexmultiplos5 < multiplos5.length; indexmultiplos5++) { | |
let comparadorMultiplo5 = multiplos5[indexmultiplos5]; | |
if (comparadorMultiplo3 === comparadorMultiplo5) { | |
multiplos5.splice(indexmultiplos5, 1); | |
} | |
} | |
} | |
let finalMultiplos3 = 0; | |
let finalMultiplos5 = 0; | |
for (let index = 0; index < multiplos3.length; index++) { | |
finalMultiplos3 += multiplos3[index]; | |
} | |
for (let index = 0; index < multiplos5.length; index++) { | |
finalMultiplos5 += multiplos5[index]; | |
} | |
let somaFinal = finalMultiplos3 + finalMultiplos5; | |
console.log(somaFinal) | |
return somaFinal; | |
} | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment