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

101
Views
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 answers
Answer question

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 Report

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 Report

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