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

177
Visualizações
JavaScript: curious to know if "if statements can substitute .include method

I am working on a .filter() method and a given solution has a .include() method in it. I was trying to solve the problem using an inner loop, next I switched to .filter and attempted using an if statement in the inner function.

Below is a code sample:



let arrayOne = [1,2,3,4,5,6];
let arrayTwo = [2,4,6,8,10,'water'];

const filterComparism=(arr1,arr2)=>{
  let newArray=[];
/**return arr1.filter(item=>arr2.includes(item)); this line of Code would solve the issue. is there an alternative step to solve below?
*/
for(let i = 0; i<arr1.length; i++){
  for(let j = 0; j< arr2.length; j++){


    
        newArray.push(arr1===arr2? return true);
  
        }
    }
  return newArray;
}

console.log(filterComparism(arrayOne,arrayTwo));
const filterComparism=(arr1,arr2)=>{ /**return arr1.filter(item=>arr2.includes(item)); this line of Code would solve the issue. is there an alternative step to solve below? */ return arr1.filter(item=>{ if(item===arr2){ return true; } return false; }); }

is there an alternative method to achieve this using an if statement in the inner function or using inner loops to compare values.

about 4 years ago · Juan Pablo Isaza
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