It's just that I feel like there has to be a bette...
# dev
j
It's just that I feel like there has to be a better way to get the date from the name than "split it on dots, take everything except the first and join them back together to get a string to represent the date, then parse that and reformat it." Like even if there was a split that forced the result to be two parts (i.e. split the string only on the first instance of the separator) instead of what appears to be the JS way of split the string and return only the first two...
I guess that raises the question, can I
name.split(".",-3).join("-")
It at least saves one step...
c
You could use indexOf to find just the first instance of the separator, and avoid the need to "join", since you could use periods in your fromString. This is more efficient than splitting on all instances of "." because it doesn't create an intermediate array and avoids the join call. https://observablehq.com/d/7c2c8e2fa0bbf843#cell-11
j
that's better... at least I'm not tearing a string apart just to put it back together. Thanks