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

120
Views
Javascript While Loop sale antes de terminar la ejecución

Estoy tratando de crear un programa simple:

Entrada: una fecha1

Salida: una fecha2 que es de 4 días de la semana desde la fecha1 (avanzando en el tiempo)

Ejecuto el código y solo recibo una fecha2 que está a 1 día de distancia. Después de investigar un poco, noté que mi bucle while solo se ejecuta una vez, no 4 veces como especifiqué en let freeDays = 4; .

¿Alguien podría explicar qué estoy haciendo mal? ¿Por qué el bucle while no pasa 4 veces?

 Date.prototype.addDays = function(days) { this.setDate( this.getDate() + days); return this; Date.prototype.isWeekday = function(){ return !((this.getDay() == 0)||(this.getDay() == 6)); } function getLastFreeDay(date1){ let freeDays = 4; while (freeDays>0){ if(date1.isWeekday()){ freeDays--; date1.addDays(1); } else{ date1.addDays(1); } return date1; } } console.log(getLastFreeDay(new Date(2022, 1, 22)))
about 4 years ago · Juan Pablo Isaza
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!