Hope everyone had a fantastic weekend! Let's get this Monday started.
Building off of Thurday's problem let's create a function that returns all the text between two sets of parenthesis. Your function should return an array since there can be multiple sets of parenthesis in a string. Your function also shouldn't use any regex since we already did that last week :)
Comments:
James - 10 years, 4 months ago
Admittedly not my best work. Does not recursively parse nested parenthesis, and due to the static variables, it is not possible for the caller to implement that behavior him/herself. I should really pass a parse state structure into parse_parens(), but then I'd have to write psudo-constructor/destructor functions... This implementation diverges from the problem statement in that it does not return an array of strings. It must be called multiple times to achieve the desired effect. I wasn't sure what the problem meant by "two stets" of parenthesis, so I ignored the word "two". Text between mismatched parenthesis is ignored (one parenthesis does not make a set).
reply permalink
Nick Krichevsky - 10 years, 4 months ago
reply permalink
Anonymous - 10 years, 4 months ago
Should correctly match nested parentheses, probably the simplest it can go
reply permalink