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

123
Visualizações
JavaScript syntax declare object inside function

I wrote a code:

 const search = (what, arr) => arr.filter((el) => 
    (onde(what,el).tag).includes((onde(what,el).input)));

but it call function onde(), two times.

But it is not needed.

How to set part = onde(what,el);

inside const search ?

so it can be called one time only, as part.tag and part.input

   const search = (what, arr) => arr.filter((el) => 
(onde(what,el).tag).includes((onde(what,el).input)));
    
    function exibe(el, index, array) {console.log(index+" = " + el.name +" " + el.value+" " + el.other);}
    function onde(what,where) { array1=[]; tags =what.split(':')[0]; tag =tags.split(','); 
        tag.forEach(element => {  array1.push(where[element]);});
          array['tag']=array1.join(' ').toLowerCase();
          array['input']=what.split(':')[1].toLowerCase();
          return array;
        }
       
        var array = [
            { name:"string 1", value:"this A", other: "that 10" },
            { name:"string 2 this", value:"those B", other: "that 20" },
            { name:"string 3", value:"this C", other: "that 30" }
        ];
        const serached = search("name,value:this",array);
        if (serached) {
          serached.forEach(exibe);
        } else {
            console.log('No result found');
        }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Save it in a variable first.

const search = (what, arr) => arr.filter((el) => {
    const { tag, input } = onde(what, el);
    return tag.includes(input);
});

or

const search = (what, arr) => arr.filter((el) => {
    const result = onde(what, el);
    return result.tag.includes(result.input);
});
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