Closed aaronfeng closed 11 years ago
Thanks Aaron! :beers: :computer: :beers:
np, glad I can help. FYI, there's a lot of room for perf improvements. Every operation is iterating through all the possible values even when it doesn't have to. An easy fix would be to break out of the loop when the value is found.
Also, some of the operations might be questionable on integers. For example, "08034".to_i.to_gmt_offset doesn't really work as well as "90210".to_i.to_gmt_offset.
Thanks for the tip on improving performance. Zipcodes with leading zeros are problematic. Ruby will convert "08034".to_i
to 8034
because of the leading zeros. So when converting from a zip to GMT offset, the zip will have to be a string (https://github.com/jgv/area#get-the-gmt-offset-of-a-zipcode). Maybe there is a way around this with sprintf or rjust.
Yes, I understand the reason. One way to get around the int zipcode issue is to convert to string then pad the left side with zeros. Or just not support it by throwing an exception :)
Another note on perf, ideally, the lookup will happen via hash not array like data structure. If would be nice if the lookup is O(1) instead of O(n). In some cases, I see O(n^2) complexity in area. Not sure how much work will this require, but it's worth thinking about.
Previously it was not considering zipcode column from the csv file during the to gmt conversion.