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

146
Visualizações
How do I capitalize every letter that has a period immediately after it in Javascript in a concise manner?

I have the following string A.b.c. This is an example

I would like to make it so that any letters which have a period immediately after them are capital.

This is the code I currently have, which works. Any ideas on how to make this more concise?

let testString = 'A.b.c. This is an example'
const pieces = testString.split('.')

let tempString = ''
let replaceString = ''
pieces.forEach(piece => {
  if (piece.length === 1) {
    tempString += piece.toUpperCase() + '.'
    replaceString += piece + '.'
  }
})

let newString = testString.replace(replaceString, tempString)
console.log(newString)

//A.B.C. This is an example

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

This can be done with a regular expression and a custom replacement function. It may look cleaner if you're not bothered by the ugliness of regular expressions.

let testString = 'A.b.c. This is an example.';
let newString = testString.replace(/\w\./g, letter => letter.toUpperCase());
console.log(newString);

about 4 years ago · Santiago Trujillo 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