Fair enough.
Here's my solution:
def reverse() {
def a = "Can a fella get a job?"
StringBuilder b = new StringBuilder()
for (int i = a.length(); i > 0; i--) {
b.append(a.charAt(i-1))
}
print b.toString()
}
But it doesn't use arrays because quite frankly, I haven't used an array in years. I despise the noise of the brackets. :-)
Seriously, I use ArrayLists instead of arrays. But even on this FizzBuzz lite exercise, I got tripped up. My "i > 0" was off by one. And I started down the path of a.substring, but that was a bad move. I quickly switched to charAt.
But about the only relevant piece of this: on an IDE, I was able to place a breakpoint, see where I'm at, what my variables look like, and make adjustments.
That's real life. My original cut of this would have disqualified me. Actually, even the cut above would disqualify me since I didn't use arrays.
But I need to confess. What you see above is literally the first time I've ever reversed a string in this manner. It's just not something I do. And it didn't roll off the tongue so to speak. I knew I had to process the string from the end and work backwards, but it still felt like trivia and not a substantive inquisition into my skills or experience.
Trivial? A bit. It took me about 5 min. The off by one was killing me. It hits you in two places: the i > 0 and the charAt(i-1).