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

103
Visualizações
Search multiple times in array in Javascript

I have an array that contains some of these 3 values: ['daily', 'monthly', 'yearly']

but sometimes the array only contains: ['monthly', 'daily']

and what I want is to get the minimum between these 3 values which is daily and if not there I want monthly and also if it's not there I want the yearly. How can I achieve that ?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You can approach this issue by comparing the values daily, monthly, and yearly alphabetically/by ASCII order

about 4 years ago · Juan Pablo Isaza Relatório

0

Simplest approach that doesn't rely on alphabetic ordering (and would therefore still work when adding new intervals like hourly):

function getLowest (arr) {
  const order = ['daily', 'monthly', 'yearly'] 
  return order.find(val => arr.includes(val))
}

This works because find will return the first matching result.

about 4 years ago · Juan Pablo Isaza Relatório

0

Here is the function you just need to pass your array it will return a minimum value.

function getMinimum(arr)
{
    return arr.includes('daily') ? 'daily' : arr.includes('monthly') ? 'monthly' : arr.includes('yearly') ? 'yearly' : "";
}
var arr1 = ['daily', 'monthly', 'yearly'];
console.log(getMinimum(arr1));

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