I'm curious to see how active the GWB community is and in particular with tackling short technical questions. So with this challenge or Quick BrainSharpener, I encourage readers to provide suggested solutions in the comments section.
QUESTION:
Given a sentence or phrase, return all the words that exist in a phrase. Each word is delimited by a space. NOTE that words that are wrapped in quotes ("") are considered one word. Oh, and no, you can't use built in string library functions like Split.
(i.e. The quick "brown fox" would be three words)
How would you optimize your solution (both in terms of memory consumption and performance/speed)?
Now, based on your solution, now change your function so that it gives me the reversed words?
(i.e. Not a tub but a ton would give me the following words: toN, a, but, tub, a not)
Now, just extend this so that it gives me the reversed words in reverse order?
(i.e. Not a tub but a ton would give me the words in the following order: not, a, tub, but, a, toN)
*SPOILER* - DO NOT TRY THE FOLLOWING UNTIL YOU HAVE ATTEMPTED THE FIRST THREE MINI PROBLEMS
Now, how would you have approached this problem if I had given you the problem in one go? Would you have started designing your solution differently?
How can you make your function more generic? (HINT: actually, this is one point to get the thinking started... what if a caller wanted words delimited by other characters as opposed to a space)