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

244
Views
Day.js: obtenga una matriz de meses restantes en el año

Quiero obtener una matriz del índice de los meses restantes (índice 0), sin incluir el mes actual, en una cuenta regresiva, este año (o cualquier fecha por el simple hecho de hacerlo). Estoy usando lodash y dayjs , pero siento que mi código es un poco difícil de entender.

¿Hay una forma más "dayjs" de obtener lo que quiero? No he encontrado más ayuda en la biblioteca del documento u otros hilos con un problema similar aquí.

 // All months - Current year's remaining months (0-index), we map in reverse until reaching 0 const yearRemainingMonths = map(range(11 - dayjs().month()), n => 11 - n) // [] // Let's pretend we are in June, so we'd get // [11, 10, 9, 8, 7]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

No hay mucho de una manera más limpia. Al final, debe hacer un bucle una vez o almacenar la matriz predefinida.

Ejemplo 1: con datos en caché

 import dayjs from 'dayjs' const months = [0,1,2,3,4,5,6,7,8,9,10,11] function remainingMonths(month) { return [...months].splice(month+1).reverse() } console.log(remainingMonths(dayjs().month())) // [] console.log(remainingMonths(5)) // june => [ 11,10,9,8,7,6] console.log(remainingMonths(0)) // [11,10,9,8,7,6,5,4,3,2,1]

Ejemplo 2 - con for loop

 function remainingMonths(month) { const remaining = [] for(let i = 11; i > month; i--) { remaining.push(i) } return remaining } console.log(remainingMonths(11)) // [] console.log(remainingMonths(5)) // june => [ 11,10,9,8,7,6] console.log(remainingMonths(0)) // [11,10,9,8,7,6,5,4,3,2,1]

Probablemente el ciclo for es un poco más limpio.

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!