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

156
Views
check if element of list exist between two values of another list in javascript

I want to check if an element from list exist between two elements for another list For example I have list of ages and the other list is agesPeriod

agesPeriod : [
{
    min : 10,
    Max : 20
},
{
    min : 30,
    Max : 90
},
],
ages : [10,20,40]
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Maybe this one use array.forEach and array.filter?

let agesPeriod = [
{
    min : 10,
    Max : 20,
},
{
    min : 30,
    Max : 90,
}
]
let ages = [10,20,40]

agesPeriod.forEach(arr =>{
console.log(ages.filter(i=>arr.min <= i && i<=arr.Max ))
})

about 4 years ago · Juan Pablo Isaza Report

0

const doesItExist = (list1, list2) => {
  let result = false;
  list1.forEach(el => {
    list2.forEach(range => {
        if (el >= range.min && el <= range.Max) {
        result = true;
      }
    });
  });
  return result;
};

console.log(doesItExist(ages, agesPeriod));
about 4 years ago · Juan Pablo Isaza Report

0

I found the solution :

  let result = []  
    agesPeriod.forEach(range => {
      ages.forEach(el => {
          if (el >= range.min && el <= range.max) {
            result.push(range);
          }
      });
    });
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!