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

107
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 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