Created
September 27, 2013 14:32
-
-
Save polycarpou/6729517 to your computer and use it in GitHub Desktop.
tweet shortener week 1 day 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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