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

260
Views
How can i target elements in another array via .filter()

Im trying to return the values in argument[0] that are not equal to the values of arguments[1] and so on.

Ive created a variable 'let argArr' that holds the values of the arguments after the first, Im trying to understand why in my .filter() i cannot target 'let argArr'?

function destroyer(arr) {
  let argArr = [];

  for (let i = 1; i < arguments.length; i++) {
    argArr.push(arguments[i])
  }

  return arr.filter(i => i !== argArr)
}

console.log(destroyer([1, 2, 3, 1, 2, 3], 2, 3));

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

0

You are comparing an arr array's element to the argArr what is wrong. The right way is to check if element is inside argArr and filter if yes.

return arr.filter(i => !argArr.includes(i))

about 4 years ago · Juan Pablo Isaza Report

0

Instead of using arguments explicitly specify the array as the first argument, and then use rest parameters to gather all the remaining arguments into an array. Then use filter to return only those elements in the array that are not in the rest array.

function destroyer(arr, ...rest) {
  return arr.filter(el => !rest.includes(el));
}

console.log(destroyer([1, 2, 3, 1, 2, 3], 2, 3));

about 4 years ago · Juan Pablo Isaza Report

0

Use spread operator to treat arguments as normal array

function foo() {
    return [...arguments].filter(el => el);
}
console.log(foo(1,2,3))

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!