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

230
Visualizações
Change the order of the given string in a specific way

I have a string for example '12:13:45.123 UTC Sun Oct 17 2021' and I am looking to change the string into 'Sun Oct 17 2021 12:13:45.123 UTC'.

I do it with

str.slice(18)+' '+str.slice(0,17)

.

but the question is - how can I avoid call slice twice? is there a way to make it more elegant way and efficient?

BTW - I am not looking to split and concat the substrings.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use replace with a regex:

const str = '12:13:45.123 UTC Sun Oct 17 2021';

console.log(str.replace(/(.{16}) (.*)/, '$2 $1'));

IMHO it's more elegant but according to https://jsbench.me/ your code is faster.

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