Skip to content

Instantly share code, notes, and snippets.

@jmealo
Created September 2, 2012 18:27
Show Gist options
  • Save jmealo/3602657 to your computer and use it in GitHub Desktop.
Save jmealo/3602657 to your computer and use it in GitHub Desktop.
Zipcode to State
var state_abbr = [ 'AA','AE','AK','AL','AP','AR','AZ','CA','CO','CT','DC','DE','FL','GA','GU','HI',
'IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC',
'ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','PR','RI','SC','SD','TN',
'TX','UT','VA','VT','WA','WI','WV','WY' ];
var prefix_matrix = { 100:38, 101:38, 102:38, 103:38, 104:38, 105:38, 106:38, 107:38, 108:38,
109:38, 110:38, 111:38, 112:38, 113:38, 114:38, 115:38, 116:38, 117:38,
118:38, 119:38, 120:38, 121:38, 122:38, 123:38, 124:38, 125:38, 126:38,
127:38, 128:38, 129:38, 130:38, 131:38, 132:38, 133:38, 134:38, 135:38,
136:38, 137:38, 138:38, 139:38, 140:38, 141:38, 142:38, 143:38, 144:38,
145:38, 146:38, 147:38, 148:38, 149:38, 150:42, 151:42, 152:42, 153:42,
154:42, 155:42, 156:42, 157:42, 158:42, 159:42, 160:42, 161:42, 162:42,
163:42, 164:42, 165:42, 166:42, 167:42, 168:42, 169:42, 170:42, 171:42,
172:42, 173:42, 174:42, 175:42, 176:42, 177:42, 178:42, 179:42, 180:42,
181:42, 182:42, 183:42, 184:42, 185:42, 186:42, 187:42, 188:42, 189:42,
190:42, 191:42, 192:42, 193:42, 194:42, 195:42, 196:42, 197:11, 198:11,
199:11, 200:10, 201:50, 202:10, 203:10, 204:10, 205:10, 206:24, 207:24,
208:24, 209:24, 210:24, 211:24, 212:24, 214:24, 215:24, 216:24, 217:24,
218:24, 219:24, 220:50, 221:50, 222:50, 223:50, 224:50, 225:50, 226:50,
227:50, 228:50, 229:50, 230:50, 231:50, 232:50, 233:50, 234:50, 235:50,
236:50, 237:50, 238:50, 239:50, 240:50, 241:50, 242:47, 243:50, 244:50,
245:50, 246:54, 247:54, 248:54, 249:54, 250:54, 251:54, 252:54, 253:54,
254:54, 255:54, 256:54, 257:54, 258:54, 259:54, 260:54, 261:54, 262:54,
263:54, 264:54, 265:54, 266:54, 267:24, 268:54, 270:31, 271:31, 272:31,
273:31, 274:31, 275:31, 276:31, 277:31, 278:31, 279:31, 280:31, 281:31,
282:31, 283:31, 284:31, 285:31, 286:31, 287:31, 288:31, 289:31, 290:45,
291:45, 292:45, 293:45, 294:45, 295:45, 296:45, 297:31, 298:13, 299:13,
300:13, 301:13, 302:13, 303:13, 304:13, 305:13, 306:13, 307:47, 308:13,
309:13, 310:13, 311:13, 312:13, 313:13, 314:13, 315:12, 316:13, 317:13,
318:13, 319:13, 320:12, 321:12, 322:12, 323:12, 324:12, 325:12, 326:12,
327:12, 328:12, 329:12, 330:12, 331:12, 332:12, 333:12, 334:12, 335:12,
336:12, 337:12, 338:12, 339:12, 340:0, 341:12, 342:12, 344:12, 346:12,
347:12, 349:12, 350:3, 351:3, 352:3, 354:3, 355:3, 356:3, 357:3, 358:3,
359:3, 360:3, 361:3, 362:3, 363:3, 364:3, 365:3, 366:3, 367:3, 368:3,
369:29, 370:47, 371:47, 372:47, 373:47, 374:47, 375:47, 376:47, 377:47,
378:47, 379:47, 380:47, 381:47, 382:47, 383:47, 384:47, 385:47, 386:47,
387:29, 388:29, 389:29, 390:29, 391:29, 392:29, 393:29, 394:29, 395:29,
396:29, 397:29, 398:13, 399:13, 400:21, 401:21, 402:21, 403:21, 404:21,
405:21, 406:21, 407:21, 408:21, 409:21, 410:39, 411:54, 412:54, 413:21,
414:21, 415:54, 416:54, 417:21, 418:21, 420:21, 421:21, 422:21, 423:21,
424:19, 425:21, 426:21, 427:21, 430:39, 431:39, 432:39, 433:39, 434:39,
435:39, 436:39, 437:39, 438:39, 439:42, 440:39, 441:39, 442:39, 443:39,
444:39, 445:39, 446:39, 447:39, 448:39, 449:39, 450:39, 451:39, 452:39,
453:39, 454:39, 455:39, 456:39, 457:39, 458:39, 459:39, 460:19, 461:19,
462:19, 463:19, 464:19, 465:19, 466:19, 467:19, 468:19, 469:19, 470:39,
471:21, 472:19, 473:19, 474:19, 475:19, 476:19, 477:19, 478:19, 479:19,
480:26, 481:26, 482:26, 483:26, 484:26, 485:26, 486:26, 487:26, 488:26,
489:26, 490:26, 491:26, 492:26, 493:26, 494:26, 495:26, 496:26, 497:26,
498:26, 499:26, 500:16, 501:16, 502:16, 503:16, 504:16, 505:16, 506:16,
507:16, 508:16, 509:16, 510:46, 511:46, 512:46, 513:46, 514:16, 515:33,
516:33, 520:16, 521:16, 522:16, 523:16, 524:16, 525:16, 526:18, 527:18,
528:16, 530:53, 531:53, 532:53, 534:53, 535:53, 537:53, 538:53, 539:53,
540:27, 541:53, 542:53, 543:53, 544:53, 545:53, 546:53, 547:53, 548:53,
549:53, 550:27, 551:27, 553:27, 554:27, 555:27, 556:27, 557:27, 558:27,
559:27, 560:27, 561:27, 562:27, 563:27, 564:27, 565:32, 566:27, 567:32,
570:46, 571:46, 572:46, 573:46, 574:46, 575:46, 576:32, 577:46, 580:32,
581:32, 582:32, 583:32, 584:32, 585:32, 586:32, 587:32, 588:32, 590:30,
591:30, 592:30, 593:30, 594:30, 595:30, 596:30, 597:30, 598:30, 599:30,
600:18, 601:18, 602:18, 603:18, 604:18, 605:18, 606:18, 607:18, 608:18,
609:18, 610:18, 611:18, 612:18, 613:18, 614:18, 615:18, 616:18, 617:18,
618:18, 619:18, 620:28, 622:28, 623:18, 624:18, 625:18, 626:18, 627:18,
628:18, 629:18, 630:28, 631:28, 633:28, 634:18, 635:18, 636:28, 637:28,
638:28, 639:28, 640:28, 641:28, 644:28, 645:28, 646:28, 647:28, 648:28,
649:28, 650:28, 651:28, 652:28, 653:28, 654:28, 655:28, 656:28, 657:28,
658:28, 660:28, 661:28, 662:20, 664:20, 665:20, 666:20, 667:28, 668:20,
669:20, 670:20, 671:20, 672:20, 673:20, 674:20, 675:20, 676:20, 677:20,
678:20, 679:20, 680:33, 681:33, 683:33, 684:33, 685:33, 686:33, 687:33,
688:33, 689:33, 690:33, 691:33, 692:33, 693:33, 700:22, 701:22, 703:22,
704:22, 705:22, 706:22, 707:22, 708:22, 710:22, 711:22, 712:22, 713:22,
714:22, 716:5, 717:5, 718:22, 719:5, 720:5, 721:5, 722:5, 723:47, 724:5,
725:5, 726:5, 727:5, 728:5, 729:5, 730:40, 731:40, 733:48, 734:40,
735:40, 736:40, 737:40, 738:40, 739:20, 740:40, 741:40, 743:40, 744:40,
745:40, 746:40, 747:40, 748:40, 749:40, 750:48, 751:48, 752:48, 753:48,
754:48, 755:22, 756:48, 757:48, 758:48, 759:48, 760:48, 761:48, 762:48,
763:48, 764:48, 765:48, 766:48, 767:48, 768:48, 769:48, 770:48, 772:48,
773:48, 774:48, 775:48, 776:48, 777:48, 778:48, 779:48, 780:48, 781:48,
782:48, 783:48, 784:48, 785:48, 786:48, 787:48, 788:48, 789:48, 790:48,
791:48, 792:48, 793:48, 794:48, 795:48, 796:48, 797:48, 798:48, 799:48,
800:8, 801:8, 802:8, 803:8, 804:8, 805:8, 806:8, 807:8, 808:8, 809:8,
810:8, 811:8, 812:8, 813:8, 814:8, 815:8, 816:8, 820:55, 821:55, 822:55,
823:55, 824:55, 825:55, 826:55, 827:55, 828:55, 829:55, 830:55, 831:55,
832:17, 833:17, 834:17, 835:52, 836:17, 837:17, 838:52, 840:49, 841:49,
842:49, 843:49, 844:49, 845:49, 846:49, 847:49, 850:6, 851:6, 852:6,
853:6, 855:6, 856:6, 857:6, 859:6, 860:6, 863:6, 864:37, 865:36, 870:36,
871:36, 873:36, 874:36, 875:36, 877:36, 878:36, 879:36, 880:48, 881:36,
882:36, 883:36, 884:36, 885:48, 889:37, 890:37, 891:37, 893:37, 894:37,
895:37, 897:37, 898:37, 900:7, 901:7, 902:7, 903:7, 904:7, 905:7, 906:7,
907:7, 908:7, 910:7, 911:7, 912:7, 913:7, 914:7, 915:7, 916:7, 917:7,
918:7, 919:7, 920:7, 921:7, 922:7, 923:7, 924:7, 925:7, 926:7, 927:7,
928:7, 930:7, 931:7, 932:7, 933:7, 934:7, 935:7, 936:7, 937:7, 938:7,
939:7, 940:7, 941:7, 942:7, 943:7, 944:7, 945:7, 946:7, 947:7, 948:7,
949:7, 950:7, 951:7, 952:7, 953:7, 954:7, 955:7, 956:7, 957:7, 958:7,
959:7, 960:7, 961:37, 962:4, 963:4, 964:4, 965:4, 966:4, 967:15, 968:15,
969:14, 970:41, 971:41, 972:41, 973:41, 974:41, 975:41, 976:41, 977:41,
978:41, 979:17, 980:52, 981:52, 982:52, 983:52, 984:52, 985:52, 986:41,
988:52, 989:52, 990:52, 991:52, 992:52, 993:52, 994:52, 995:2, 996:2,
997:2, 998:2, 999:2, 005:38, 006:43, 007:43, 008:43, 009:43, 010:9,
011:9, 012:9, 013:23, 014:23, 015:23, 016:23, 017:23, 018:23, 019:23,
020:23, 021:23, 022:23, 023:23, 024:23, 025:23, 026:23, 027:44, 028:44,
029:44, 030:34, 031:34, 032:34, 033:34, 034:34, 035:51, 036:51, 037:51,
038:34, 039:25, 040:25, 041:25, 042:25, 043:25, 044:25, 045:25, 046:25,
047:25, 048:25, 049:25, 050:51, 051:51, 052:51, 053:51, 054:51, 055:23,
056:51, 057:51, 058:51, 059:51, 060:9, 061:9, 062:9, 063:9, 064:9, 065:9,
066:9, 067:9, 068:9, 069:9, 070:35, 071:35, 072:35, 073:35, 074:35,
075:35, 076:35, 077:35, 078:35, 079:35, 080:35, 081:35, 082:35, 083:35,
084:35, 085:35, 086:35, 087:35, 088:35, 089:35, 090:1, 091:1, 092:1,
093:1, 094:1, 095:1, 096:1, 097:1, 098:1, 099:1
};
function zipcode_to_state (zipcode) {
var prefix = zipcode.toString().substr(0,3);
return state_abbr[prefix_matrix[prefix]] || false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment