Your one-liners?

Posted by john in Ruby Add comments

Now that we are past the one-liner era in our progress along the Ruby Way, I’d like to invite you to propose some one liners of your own.

Just to kick it off:

Given a dictionary d with bad words:

d = [ ‘Yankees’, ‘Rockies’, ‘Indians’ ]

write a one-liner that replaces any usage of such bad words in a sentence with the first letter of the bad word followed by stars, one star for each of the remaining letters.

Input:

“As much as I can’t stand the Yankees and relish beating them, I’m glad we faced the Indians.”

Output:

“As much as I can’t stand the Y****** and relish beating them, I’m glad we faced the I******.”

P.S. I haven’t implemented this one. Seems like a one-liner . . .

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Login