Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda