Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Ugh, forgot to remove one of the
sort
s. Could have done that in one.I thought that avoiding modifying the array would be more performant, but but perf tests showed that this method is 98% slower than the top voted solutions as of time of writing. Better to just chop up the array. Way less to keep track of that way.
This comment is hidden because it contains spoiler information about the solution
Thanks @Grey, very informative writup. Now I'm looking deeper into tokenizing.
I appreciate tips on using comments better as well.
@cskyleryoung: The "runner up" wasn't always the runner-up. I don't think it's a stretch to say that both solutions helped each other gain points; ooflorent's solution and mine have a lot in common. The difference being, I've demonstrated how to use a tokenizer, which is generally good practice when writing a parser.
However, this language is really very simple and so many people took exception to my solution for being 'overkill' (just read the other comments). I expect it will soon lose the top spot. Which I am OK with, because I like the other solution as well (it is almost canonical). But when you start writing real world parsers, just know you can expect to write tokenizing/lexing code.
Please make sure your performance test will be accessible indefinitely, and next time you reference a different solution, please link to it. That way, your comments will stay intelligible in the future, even if the ranking changes.
As you have likely surmised it's because it takes a pass through to essentially remove all non parens first. One could simply ignore anything that isn't a paren.
As of the time of writing, not sure why this solution has the most votes for Best Practice. It seems MUCH slower than the runner up. See this perf test for example: https://jsperf.com/parens-valid/1
If I am missing something, would appreciate learning what it is. Thanks.