Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

330
Views
¿Cómo imprimir todos los números que son divisibles por 3 o por 5, pero no por ambos?

Tengo una función tres o cinco (máx.). Debe hacer un bucle con cada número que sea divisible por 3 o por 5, pero no por ambos. Por lo tanto, no repetirá 15 ya que es divisible por ambos números, pero imprimirá "3, 5, 6, 9, 10, 12, 18".

El código que he probado es

 function threeOrFive(max){ for(let i = 0; i<max; i+=3, i+=5){ console.log(i); } }

y

 function threeOrFive(max){ for(let i = 0; i<max; i+=3){ if(i+=3 % max === 0 && i+=5 % max === 0){ return false; } console.log(i); } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede utilizar esta función. Esto devolverá una matriz de todos los números que son divisibles por 3 o 5 pero no por ambos.

 const threeOrFive = max => { const store = []; for(let i = 0; i < max; i++){ if (i%3==0 && i%5==0) continue; else if (i%3==0) store.push(i); else if (i%5==0) store.push(i); } return store; }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!