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

227
Visualizações
Specific text with include() and replace() with .map() ES6

I am trying to find a logic that i could use with .map() to return the desired value.
Below are 2 variables im using

    let _replaceAttr = ['SUM', 'ARRG', 'AGG', 'ATTR', "AVG(pop)"]
    let tempData = ['AVG', 'bob', 'sop']

The logic i came with out is returning all as true, if tempData index 0 is set as AVG(pop) , this will return as false.

    result = tempData.map(el => !_replaceAttr.includes(el))
    console.log(result);

    // This logic will not apply the updated array element as it will return all as true 
    let es6 = tempData.map(w => !_replaceAttr.includes(w) != true ? w.replace(w, '...') : w)

If i were to specifically test this with traditional scripting such as

console.log('AVG(pop)'.includes('AVG') 
// This will return as false  which is correct   
// or

//******* Traditional Script ******** 
    for (let i = 0; i < tempData.length; i++) {
        let output = tempData[i]
        for (let a = 0; a < _replaceAttr.length; a++) {
            if (output.includes(_replaceAttr[a])) {
                tempData[i] = tempData[i].replace(_replaceAttr[a], '').replace('(', '').replace(')', '')
            }
        }

    }
    console.log(tempData)

The traditional script i have will return the desired output ,i was wondering . Will it be achievable to go with .map() approach on above example.

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