Skip to content

Instantly share code, notes, and snippets.

@polycarpou
Created September 27, 2013 14:32
Show Gist options
  • Save polycarpou/6729517 to your computer and use it in GitHub Desktop.
Save polycarpou/6729517 to your computer and use it in GitHub Desktop.
tweet shortener week 1 day 4
def shorten_tweet(tweet)
return tweet if tweet.length < 140
tweet = tweet.split(" ")
out = []
tweet.each do |word|
case word
when "to", "two", "too"
out << '2'
when "for", "four"
out << '4'
when "be"
out << "b"
when "you"
out << "u"
when "at"
out << "@"
when "and"
out << "&"
else
out << word
end
end
out = out.join(" ")
if out.length > 140
out = out[0..140]
end
out
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment