Created
April 20, 2012 01:25
-
-
Save bradherman/2425188 to your computer and use it in GitHub Desktop.
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
# start off with the hash | |
timezones = {} | |
# then build the hash | |
(-12..12).to_a.each do |i| | |
timezones["utc"+i] = 0 | |
end | |
# now we have a hash with a key for each timezone from "utc-12" to "utc12" | |
# now we run through the list of tweets | |
tweets.each do |tweet| | |
# we'll assume tweet has some way to access its timezone and that tweet["timezone"] spits out "utc-10", etc | |
timezones[tweet["timezone"]] += 1 | |
# because the value at each key is an integer (starting at 0), each time we encounter the timezone, we simply add one to the value at that key | |
end | |
# later when we want to get the number of tweet for a timezone, we do this: | |
puts timezones["utc-9"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment