Hi!
A bit late to the party, but here's a Groovy one:
String peel(String toPeel) { if(!(toPeel?.length() > 2)) { throw new Exception('Can\'t peel a string shorter than 3 characters') } return toPeel[1..-2] }
My approach in groovy...
Not sure if "ignore <2 chars" means "don't consider" or "ignore the trimming"
Don't consider =>
String peel(String toPeel) { toPeel[1..-2] }
Ignore =>
String peel(String toPeel) { toPeel?.length() >2 ? toPeel[1..-2] : toPeel }
I don't like returning null.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi!
A bit late to the party, but here's a Groovy one:
My approach in groovy...
Not sure if "ignore <2 chars" means "don't consider" or "ignore the trimming"
Don't consider =>
Ignore =>
I don't like returning null.