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

217
Views
¿Cómo hacer que la función recursiva funcione en orden de procedimiento en Node.js?

Estoy tratando de hacer una matriz de calendario en Node.js. este es mi main.mts :

 import dayjs from 'dayjs'; import customParseFormat from 'dayjs/plugin/customParseFormat'; dayjs.extend(customParseFormat); function nextDay(d: string) { const e = dayjs(d, 'MMM D, YYYY (ddd)'); const f = dayjs(e).add(1, 'day'); return dayjs(f).format('MMM D, YYYY (ddd)'); } export class CalendarEdit { private cal: string[] = []; constructor(d: string) { this.cal.push(d); this.init(365).catch(err => { throw err; }); } public addDate() { const d = this.cal[this.cal.length - 1]; const e = nextDay(d); this.cal.push(e); } private init(j: number) { this.addDate(); if (j > 1) this.init(j - 1); } public printCal() { console.log(this.cal); } }

pero el resultado dice que cada elemento en la matriz cal es el mismo, que tiene que ser el último día del calendario.
Sé que JavaScript es básicamente un lenguaje sin bloqueo, pero no puedo encontrar la manera.
Intenté devoluciones de llamada y promesas, y async , await pares. pero ninguno de ellos funcionó.

Lo busqué en Google pero no puedo encontrar una solución que funcione en mi caso. alguien sabe la respuesta?

EDITAR : Llamo a CalendarEdit en mi index.mts así:

 import { CalendarEdit } from './main'; let cal = new CalendarEdit('Jun 1, 2022 (Wed)'); cal.printCal();
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Edité mi addDate() a esto y resolvió el error:

 public addDate() { const d = nextDay(this.cal[this.cal.length - 1]); this.cal.push(d); }
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!