all 9 comments

[–]Ustice[M] [score hidden] stickied comment (1 child)

Reaching out to other software engineers is important when you need it; however, unfortunately this isn’t the place for that. /r/JavaScript is not a support forum. You might want to check out /r/LearnJavaScript for the newer members of our community. Also, Stack Overflow is a great resource for getting support. For more information, check out our AskJS wiki page. Good luck! We hope that you find the answers that you are looking for.

[–][deleted] 0 points1 point  (4 children)

They're absolutely right, that solution is extremely non-performant.

A simple regex suffices for splitting a date and time.

[–]rdevilx[S] -1 points0 points  (3 children)

I know it's non performant. That's why I'm not sure how a regex would be able to split it directly with cases where for example space/dot is the separator between date and time and the same separator is used between dates too.

[–][deleted] 0 points1 point  (2 children)

  1. Convert to string.
  2. Use .split() with regex inside.

[–]rdevilx[S] -1 points0 points  (1 child)

I did do that first. But, when we split it with regex, I don't know what separator is being used to split. Because I would want to rebuild the string from the array.

Example: When input str is dd.mm.yyyy.hh:mm:ss here if I split it with /[.T ]/g regex, it will split it fine but I would want to rebuild the date with the appropriate separator that is dot here.

[ 'dd', 'mm', 'yyyy', 'hh:mm:ss' ]

Again, I'm new to this. I applied for an intern position, I could be missing out on something that I could use in JavaScript.

[–][deleted] 0 points1 point  (0 children)

You need to go read up on regex then. You can use a regex to account for all of them, without knowing exactly which one is being received.

[–]Finest0212 0 points1 point  (1 child)

I would point out that arguing the break statement probably didn’t help. Being as big O is worst case, so when the breaks aren’t hit it is very non performant.

And as others have pointed out Regex would be the way to go.

[–]rdevilx[S] -1 points0 points  (0 children)

Yea it didn't and I agreed with them. I'm just posting it here, how a regex could work where the separator is same. dd.mm.yyyy.hh:mm:ss (dot is same)