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

69
Views
Optimise logic to partially match 2 array items

I have two arrays and want to match them partially( i.e. some elements of the first array should be present in the second array but not all). I have a solution but I feel I could use a more efficient one. Here is the use case:

const array_1 = [ 7, 6 ];
const array_2 = [ 4, 6 ,7, 2, 9 ];

const isSomeItemMatched = array_1.some( item => array_2.includes(item) );
const isAllItemMatched = array_1.every( item => array_2.includes(item) );

const isPartiallyMatched = !isAllItemMatched && isSomeItemMatched;

Please let me know if there is an optimized way of doing it.

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

0

Your solution is fine for small arrays. If they get larger, you'll benefit from turning one into a set:

const array_1 = [ 7, 6 ];
const array_2 = [ 4, 6 ,7, 2, 9 ];

function isPartialMatch(a, b) {
    const setA = new Set(a);
    return b.some(x => setA.has(x)) && b.some(x => !setA.has(x));
}

console.log(isPartialMatch(array_1, array_2));

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!