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

130
Views
Array.Filter() using a callback function to compare two arrays

Insted of doing using an anonymous function how would I convert the below element => arr2.includes(element) into a named function that I could then pass in

  const ArrayOverlap = (arr1, arr2) =>{
  let newArr = [];
  return newArr = arr1.filter(element => arr2.includes(element));
}

If I was to do something like

  const ArrayOverlap = (arr1, arr2) =>{
  let newArr = [];
  return newArr = arr1.filter(bothIncluded(arr1, arr2));
}

 function bothIncluded(arr1, arr2){
  for(const item of arr1){
   return arr2.includes(item);
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I was able to get it to work by using the option thisArg when calling the callback function.

const ArrayOverlap = (arr1, arr2) =>{
let newArr = [];
return newArr = arr1.filter(checkMe, arr2);

function checkMe(element){
return this.includes(element);
}
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!