|
Here's a ruby version, smaller more compact and easier to update (probably more correct too): def state?(zip)
case zip[0]
when 0 then states = ['CT','MA','ME','NH','NJ','PR','RI','VT','VI','AE']
when 1 then states = ['DE','NY','PA']
when 2 then states = ['DC','MD','NC','SC','VA','WV']
when 3 then states = ['AL','FL','GA','MS','TN','AA']
when 4 then states = ['IN','KY','MI','OH']
when 5 then states = ['IA','HN','MT','ND','SD','WI']
when 6 then states = ['IL','KS','MO','NE']
when 7 then states = ['AR','LA','OK','TX']
when 8 then states = ['AZ','CO','ID','NM','NV','UT','WY']
when 9 then states = ['AK','AS','CA','GU','HI','MH','FM','MP','OR','PW','WA','AP']
else return null
end
return states
end
|
It just converts first digit of zip code to list of states to which it could apply.