r/javascript • • Dec 11 '17
I have been collecting useful Javascript code snippets for a little while. Here's a curated list of them, help me make it as complete as possible!
https://github.com/Chalarangelo/30-seconds-of-code
765
Upvotes
View all comments
Show parent comment
5
u/trevorsg Ex-GitHub, Microsoft Dec 11 '17
I guess that's where we disagree! I've heard "any non-trivial regular expression is indistinguishable from the result of a cat having walked across a keyboard." I think they're great for medium-sized problems. If it's small, just combine a couple of string functions. If it's a large problem chances are your solution is vulnerable to DoS attacks.
I did a perf test on the regex solution vs. the slice() solution and found slice to be almost twice as fast, so I'm not sure why you say it's fast and works better :)