I really like the concept here, teaching how to make the "basics" work :).
I think a natural next step on this would be looking at making a faster version though as this particular method probably is quite far from optimal with all the string concats and what not. A trivial tweak would be to scan and find the first and last non whitespace char and just extract the appropriate part with .substring()
I really like the concept here, teaching how to make the "basics" work :).
I think a natural next step on this would be looking at making a faster version though as this particular method probably is quite far from optimal with all the string concats and what not. A trivial tweak would be to scan and find the first and last non whitespace char and just extract the appropriate part with .substring()
Thanks for the feedback.
The idea here was to show the easiest possible implementation of
trim
without overwhelming the reader.