Ad
  • Custom User Avatar

    Ugh, forgot to remove one of the sorts. Could have done that in one.

  • Custom User Avatar

    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.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Thanks @Grey, very informative writup. Now I'm looking deeper into tokenizing.
    I appreciate tips on using comments better as well.

  • Default User Avatar

    @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.

  • Custom User Avatar

    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.

  • Custom User Avatar

    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.