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

132
Vistas
Determine which Friday of the month the date is

Given a date like April 22, 2022 how can we accurately determine which Friday of that Month it is. In this case it is the 4th Friday.

I have tried all combinations of adding the week day (0-6, so 5) plus the current day, dividing things by 7, using % because it seems cool, etc. At this point I am stumped.

I am using the Luxon library, but also have access to native JS and dayjs

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try this out:

function getFriday(day, month, year){
    
    date = new Date(year, month - 1, day)

    if (date.getDay() === 5){
        return Math.ceil(day / 7)
    } else{
        return "Date is not a Friday"
    }
}

console.log(getFriday(21, 1, 2022)) // 3
console.log(getFriday(4, 2, 2022)) // 1
console.log(getFriday(22, 4, 2022)) // 4
console.log(getFriday(15, 5, 2022)) // Date is not a Friday

It creates a date object from the function arguments, checks if the date is a Friday, then calculates which Friday it is. If the date is not a Friday, it returns "Date is not a Friday", though this could be removed to return null.

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