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

245
Views
Can a some() function replace nested forEach()?

I need to replace two (nested) forEach loops with a some function. The purpose of the code block is to check if the [1] elements in arrayOne are within the max & min of arrayTwo.

The code currently works fine and looks like this:

    var result = false;
    arrayOne.forEach((arrayOneElement) => {
      arrayTwo.forEach((arrayTwoElement) => {
        if (arrayOneElement[1] > arrayTwoElement[1].max || arrayOneElement[1] < arrayTwoElement[1].min) {
          result = true;
        }
      });
    }); 

Let me know if it isn't clear enough. Really appreciate your help.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Yes, you can use Array#some in this situation. It would be done like this

const result = arrayOne.some((arrayOneElement) => {
  return arrayTwo.some((arrayTwoElement) => {
    return arrayOneElement[1] > arrayTwoElement[1].max || arrayOneElement[1] < arrayTwoElement[1].min
  });
});
about 4 years ago · Juan Pablo Isaza Report

0

You could replace forEach with some and get destructured values from items.

const 
    result = arrayOne.some(([, value]) =>
        arrayTwo.some(([, { min, max }]) => value > max || value < min)
    ); 
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!