Skip to content

Instantly share code, notes, and snippets.

@luisangelorjr
Last active February 3, 2023 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luisangelorjr/ed56afec8665af1659fbcafe1b5c2033 to your computer and use it in GitHub Desktop.
Save luisangelorjr/ed56afec8665af1659fbcafe1b5c2033 to your computer and use it in GitHub Desktop.
<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