Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

229
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!