1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
def find_npa(dialed_nxx) nxx_819 = [ 205, 208, 210, 213, 243 ] nxx_613 = [ 203, 204, 212, 216, 218 ] nxx_819.each do |nxx| if nxx == dialed_nxx return 819 end end nxx_613.each do |nxx| if nxx == dialed_nxx return 613 end end return end if npa = find_npa(204) print npa end
Refactorings
No refactoring yet !
danielharan
June 12, 2008, June 12, 2008 00:02, permalink
1 2 3 4
def find_npa(dialed_nxx) return 819 if [ 205, 208, 210, 213, 243 ].include? dialed_nxx return 613 if [ 203, 204, 212, 216, 218 ].include? dialed_nxx end
elliottcable
June 15, 2008, June 15, 2008 04:50, permalink
A a bit more versatile, but a bit less clean, than Daniel's. Also allows an arbitrary number of NXX's later (though I have no idea what an NXX is).
1 2 3 4 5 6
def npa_for nnx { 819 => [ 205, 208, 210, 213, 243 ], 613 => [ 203, 204, 212, 216, 218 ] }.select {|k,v| v.include? nnx }.flatten.first end
I'm new to Ruby, so give me some good examples of how to do this differently