Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

259
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda