Difficulty:
Given a string, we would like to reverse the letters in each word while maintaining the original order of words, spaces and punctuation. Words are separated by spaces and punctuation marks, and there are no numbers. The words consist of lower or upper case letters (so no hyphens), and the case of letters should be preserved in the final answer.
For example,
This IS a word-teSt,yo!
should turn intosihT SI a dorw-tSet,oy!
.Avoid using tokenizers (e.g.
split
in JavaScript strings).
wordReverse("This IS a word-teSt,yo!");
"sihT SI a drow-tSet,oy!"