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

302
Visualizações
How to find similarities between a text string and an array?

I have a string array, which I want to compare with a text string, if it finds similarities I want to be able to mark in black the similarity found within the string

example:

context.body: 'G-22-6-04136 - PatientName1'

newBody: ['G-22-6-04136 - PatientName1' , 'G-22-6-04137 - PatientName2']

When finding the similarity between the two the result would be something like this

newBody: [**'G-22-6-04136 - PatientName1'** , 'G-22-6-04137 - PatientName2']

How could I do it? Is this possible to do? In advance thank you very much for the help

const totalSize: number = this.getSizeFromAttachments(attachments);
const chunkSplit = Math.floor(isNaN(totalSize) ? 1 : totalSize / this.LIMIT_ATTACHMENTS) + 1; 
const attachmentsChunk: any[][] = _.chunk(attachments, chunkSplit);

if ((totalSize > this.LIMIT_ATTACHMENTS) && attachmentsChunk?.length >= 1) {
   
    const result = attachment.map(element => this.getCantidad.find(y => element.content === y.content))
            const aux = this.namePatient
            const ans = [] 
            result.forEach(ele => {
              const expected_key = ele["correlative_soli"];
              if (aux[expected_key]) {
                const newItem = { ...ele };
                newItem["name_Patient"] = aux[expected_key]
                newItem["fileName"] = `${expected_key}${aux[expected_key] ? ' - ' + aux[expected_key] : null}\n`.replace(/\n/g, '<br />')
                ans.push(newItem)
              }
            });
            
            let newBody: any;
            const resultFilter = attachment.map(element => element.content);

            const newArr = [];
            ans.filter(element => {
              if (resultFilter.includes(element.content)) {
                newArr.push({
                  fileNameC: element.fileName
                })
              }
            })

            newBody = `• ${newArr.map(element => element.fileNameC)}`;

            const date = this.cleanDateSolic;
            const amoung= attachmentsChunk?.length;
            const getCurrent = `(${index}/${attachmentsChunk?.length})`
            const header = `${this.cleanDateSolic} pront ${attachmentsChunk?.length} mail. This is the (${index}/${attachmentsChunk?.length})`;

            console.log('body', context.body);
   
           // context.body is the body I receive of frontend like a string

            const newContext = {
              newDate: date,
              amoung: amoung,
              getCurrent: getCurrent,
              newBody: newBody,
              ...context
            }
 
            return this.prepareEmail({
              to: to,
              subject: ` ${subject} (Correo ${index}/${attachmentsChunk?.length})`,
              template: template,
              context: newContext,
            }, attachment);
 
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Based on your example, it looks like the string needs to be an exact match, is that correct?

Also, "mark it in bold" is going to depend on what you're using to render this, but if you just want to wrap the string in ** or <b> or whatever, you could do something like this:

newBody.map(str => str === context.body ? `**${str}**` : str);
about 4 years ago · Juan Pablo Isaza Relatório

0

You can just see if string exists in the array by doing if arr.includes(desiredStr) //make text bold

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