Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

219
Vistas
How to make recursive function to work in procedural order in Node.js?

I am trying to make a calendar array in Node.js. this is my 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);
    }
}

but result says every element in cal array is same, which has to be last day of calendar.
I know that JavaScript is basically non-blocking language, but I cannot find a way.
I tried callbacks and promises, and async, await pairs. but none of them worked.

I googled it but I cannot find a solution does work on my case. anyone knows the answer?

EDIT: I call CalendarEdit in my index.mts like this:

import { CalendarEdit } from './main';

let cal = new CalendarEdit('Jun 1, 2022 (Wed)');
cal.printCal();
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I edited my addDate() to this and it solved error:

public addDate() {
    const d = nextDay(this.cal[this.cal.length - 1]);
    this.cal.push(d);
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda