Skip to content

Instantly share code, notes, and snippets.

@tgmarinho
Last active September 16, 2023 00:39
Show Gist options
  • Save tgmarinho/44a2b002d350f3ef1cee1b1bc51636f0 to your computer and use it in GitHub Desktop.
Save tgmarinho/44a2b002d350f3ef1cee1b1bc51636f0 to your computer and use it in GitHub Desktop.
adjascent_state.js
const estados = [
{ name: 'Alabama', abbreviation: 'AL', id: 1 },
{ name: 'Alaska', abbreviation: 'AK', id: 2 },
{ name: 'American Samoa', abbreviation: 'AS', id: 3 },
{ name: 'Arizona', abbreviation: 'AZ', id: 4 },
{ name: 'Arkansas', abbreviation: 'AR', id: 5 },
{ name: 'California', abbreviation: 'CA', id: 6 },
{ name: 'Colorado', abbreviation: 'CO', id: 7 },
{ name: 'Connecticut', abbreviation: 'CT', id: 8 },
{ name: 'Delaware', abbreviation: 'DE', id: 9 },
{ name: 'District of Columbia', abbreviation: 'DC', id: 10 },
{ name: 'Federated States of Micronesia', abbreviation: 'FM', id: 11 },
{ name: 'Florida', abbreviation: 'FL', id: 12 },
{ name: 'Georgia', abbreviation: 'GA', id: 13 },
{ name: 'Guam', abbreviation: 'GU', id: 14 },
{ name: 'Hawaii', abbreviation: 'HI', id: 15 },
{ name: 'Idaho', abbreviation: 'ID', id: 16 },
{ name: 'Illinois', abbreviation: 'IL', id: 17 },
{ name: 'Indiana', abbreviation: 'IN', id: 18 },
{ name: 'Iowa', abbreviation: 'IA', id: 19 },
{ name: 'Kansas', abbreviation: 'KS', id: 20 },
{ name: 'Kentucky', abbreviation: 'KY', id: 21 },
{ name: 'Louisiana', abbreviation: 'LA', id: 22 },
{ name: 'Maine', abbreviation: 'ME', id: 23 },
{ name: 'Marshall Islands', abbreviation: 'MH', id: 24 },
{ name: 'Maryland', abbreviation: 'MD', id: 25 },
{ name: 'Massachusetts', abbreviation: 'MA', id: 26 },
{ name: 'Michigan', abbreviation: 'MI', id: 27 },
{ name: 'Minnesota', abbreviation: 'MN', id: 28 },
{ name: 'Mississippi', abbreviation: 'MS', id: 29 },
{ name: 'Missouri', abbreviation: 'MO', id: 30 },
{ name: 'Montana', abbreviation: 'MT', id: 31 },
{ name: 'Nebraska', abbreviation: 'NE', id: 32 },
{ name: 'Nevada', abbreviation: 'NV', id: 33 },
{ name: 'New Hampshire', abbreviation: 'NH', id: 34 },
{ name: 'New Jersey', abbreviation: 'NJ', id: 35 },
{ name: 'New Mexico', abbreviation: 'NM', id: 36 },
{ name: 'New York', abbreviation: 'NY', id: 37 },
{ name: 'North Carolina', abbreviation: 'NC', id: 38 },
{ name: 'North Dakota', abbreviation: 'ND', id: 39 },
{ name: 'Northern Mariana Islands', abbreviation: 'MP', id: 40 },
{ name: 'Ohio', abbreviation: 'OH', id: 41 },
{ name: 'Oklahoma', abbreviation: 'OK', id: 42 },
{ name: 'Oregon', abbreviation: 'OR', id: 43 },
{ name: 'Palau', abbreviation: 'PW', id: 44 },
{ name: 'Pennsylvania', abbreviation: 'PA', id: 45 },
{ name: 'Puerto Rico', abbreviation: 'PR', id: 46 },
{ name: 'Rhode Island', abbreviation: 'RI', id: 47 },
{ name: 'South Carolina', abbreviation: 'SC', id: 48 },
{ name: 'South Dakota', abbreviation: 'SD', id: 49 },
{ name: 'Tennessee', abbreviation: 'TN', id: 50 },
{ name: 'Texas', abbreviation: 'TX', id: 51 },
{ name: 'Utah', abbreviation: 'UT', id: 52 },
{ name: 'Vermont', abbreviation: 'VT', id: 53 },
{ name: 'Virgin Islands', abbreviation: 'VI', id: 54 },
{ name: 'Virginia', abbreviation: 'VA', id: 55 },
{ name: 'Washington', abbreviation: 'WA', id: 56 },
{ name: 'West Virginia', abbreviation: 'WV', id: 57 },
{ name: 'Wisconsin', abbreviation: 'WI', id: 58 },
{ name: 'Wyoming', abbreviation: 'WY', id: 59 }
];
const estadosAdjacentes = {
1: [22, 29, 48, 13, 50, 37, 10, 17], // Alabama
2: [], // Alaska (não faz fronteira com nenhum estado)
3: [], // American Samoa (não faz parte dos estados contíguos)
4: [37, 43, 16, 33], // Arizona
5: [22, 29, 48, 13, 37, 17], // Arkansas
6: [37, 43, 4, 16], // California
7: [37, 16, 50, 38, 39], // Colorado
8: [26, 20], // Connecticut
9: [26, 45, 38], // Delaware
10: [37, 1, 38, 47, 25], // District of Columbia
11: [], // Federated States of Micronesia (não faz parte dos estados contíguos)
12: [38, 1, 13, 47, 25], // Florida
13: [38, 1, 12, 37, 10, 47], // Georgia
14: [], // Guam (não faz parte dos estados contíguos)
15: [], // Hawaii (não faz parte dos estados contíguos)
16: [6, 4, 33, 32, 58, 19, 43], // Idaho
17: [26, 1, 38, 5, 13, 7, 8, 18, 45], // Illinois
18: [26, 17, 45], // Indiana
19: [58, 16, 28, 31, 43], // Iowa
20: [26, 8, 18], // Kansas
21: [26, 45, 18, 50, 48], // Kentucky
22: [5, 29, 48, 1], // Louisiana
23: [], // Maine (não faz parte dos estados contíguos)
24: [], // Marshall Islands (não faz parte dos estados contíguos)
25: [38, 1, 12, 10, 47], // Maryland
26: [8, 20, 45, 18, 17, 9], // Massachusetts
27: [18, 37], // Michigan
28: [31, 19, 58], // Minnesota
29: [5, 22, 48, 1], // Mississippi
30: [58, 31], // Missouri
31: [28, 30, 58, 16], // Montana
32: [7, 16, 52], // Nebraska
33: [6, 4, 43, 16], // Nevada
34: [26], // New Hampshire
35: [26, 45], // New Jersey
36: [37, 43, 4, 16, 33], // New Mexico
37: [6, 4, 16, 36, 43, 33, 12, 47, 13, 1, 38, 10, 38], // New York
38: [13, 1, 37, 10, 25, 12, 47, 50, 48, 39, 18, 45, 41], // North Carolina
39: [30, 38, 48], // North Dakota
40: [], // Northern Mariana Islands (não faz parte dos estados contíguos)
41: [45, 18], // Ohio
42: [45, 33, 51, 36, 44], // Oklahoma
43: [6, 16, 33, 4, 19, 31], // Oregon
44: [], // Palau (não faz parte dos estados contíguos)
45: [18, 41, 26, 9, 8, 12, 47, 21], // Pennsylvania
46: [], // Puerto Rico (não faz parte dos estados contíguos)
47: [26, 10, 37, 12, 25, 13, 38, 1], // Rhode Island
48: [29, 5, 22, 1, 38, 38], // South Carolina
49: [30, 58, 39], // South Dakota
50: [1, 21, 38], // Tennessee
51: [36, 33, 42, 44], // Texas
52: [32], // Utah
53: [], // Vermont (não faz parte dos estados contíguos)
54: [], // Virgin Islands (não faz parte dos estados contíguos)
55: [38, 38, 45, 38], // Virginia
56: [43], // Washington
57: [45, 41], // West Virginia
58: [19, 31, 30, 27, 28], // Wisconsin
59: [31, 7, 16] // Wyoming
};
console.log(estadosAdjacentes[1]); // Exemplo de como acessar os estados adjacentes de Alabama pelo ID
const states = [
{ name: 'Alabama', abbreviation: 'AL', id: 1 },
{ name: 'Alaska', abbreviation: 'AK', id: 2 },
{ name: 'American Samoa', abbreviation: 'AS', id: 3 },
{ name: 'Arizona', abbreviation: 'AZ', id: 4 },
{ name: 'Arkansas', abbreviation: 'AR', id: 5 },
{ name: 'California', abbreviation: 'CA', id: 6 },
{ name: 'Colorado', abbreviation: 'CO', id: 7 },
{ name: 'Connecticut', abbreviation: 'CT', id: 8 },
{ name: 'Delaware', abbreviation: 'DE', id: 9 },
{ name: 'District of Columbia', abbreviation: 'DC', id: 10 },
{ name: 'Federated States of Micronesia', abbreviation: 'FM', id: 11 },
{ name: 'Florida', abbreviation: 'FL', id: 12 },
{ name: 'Georgia', abbreviation: 'GA', id: 13 },
{ name: 'Guam', abbreviation: 'GU', id: 14 },
{ name: 'Hawaii', abbreviation: 'HI', id: 15 },
{ name: 'Idaho', abbreviation: 'ID', id: 16 },
{ name: 'Illinois', abbreviation: 'IL', id: 17 },
{ name: 'Indiana', abbreviation: 'IN', id: 18 },
{ name: 'Iowa', abbreviation: 'IA', id: 19 },
{ name: 'Kansas', abbreviation: 'KS', id: 20 },
{ name: 'Kentucky', abbreviation: 'KY', id: 21 },
{ name: 'Louisiana', abbreviation: 'LA', id: 22 },
{ name: 'Maine', abbreviation: 'ME', id: 23 },
{ name: 'Marshall Islands', abbreviation: 'MH', id: 24 },
{ name: 'Maryland', abbreviation: 'MD', id: 25 },
{ name: 'Massachusetts', abbreviation: 'MA', id: 26 },
{ name: 'Michigan', abbreviation: 'MI', id: 27 },
{ name: 'Minnesota', abbreviation: 'MN', id: 28 },
{ name: 'Mississippi', abbreviation: 'MS', id: 29 },
{ name: 'Missouri', abbreviation: 'MO', id: 30 },
{ name: 'Montana', abbreviation: 'MT', id: 31 },
{ name: 'Nebraska', abbreviation: 'NE', id: 32 },
{ name: 'Nevada', abbreviation: 'NV', id: 33 },
{ name: 'New Hampshire', abbreviation: 'NH', id: 34 },
{ name: 'New Jersey', abbreviation: 'NJ', id: 35 },
{ name: 'New Mexico', abbreviation: 'NM', id: 36 },
{ name: 'New York', abbreviation: 'NY', id: 37 },
{ name: 'North Carolina', abbreviation: 'NC', id: 38 },
{ name: 'North Dakota', abbreviation: 'ND', id: 39 },
{ name: 'Northern Mariana Islands', abbreviation: 'MP', id: 40 },
{ name: 'Ohio', abbreviation: 'OH', id: 41 },
{ name: 'Oklahoma', abbreviation: 'OK', id: 42 },
{ name: 'Oregon', abbreviation: 'OR', id: 43 },
{ name: 'Palau', abbreviation: 'PW', id: 44 },
{ name: 'Pennsylvania', abbreviation: 'PA', id: 45 },
{ name: 'Puerto Rico', abbreviation: 'PR', id: 46 },
{ name: 'Rhode Island', abbreviation: 'RI', id: 47 },
{ name: 'South Carolina', abbreviation: 'SC', id: 48 },
{ name: 'South Dakota', abbreviation: 'SD', id: 49 },
{ name: 'Tennessee', abbreviation: 'TN', id: 50 },
{ name: 'Texas', abbreviation: 'TX', id: 51 },
{ name: 'Utah', abbreviation: 'UT', id: 52 },
{ name: 'Vermont', abbreviation: 'VT', id: 53 },
{ name: 'Virgin Islands', abbreviation: 'VI', id: 54 },
{ name: 'Virginia', abbreviation: 'VA', id: 55 },
{ name: 'Washington', abbreviation: 'WA', id: 56 },
{ name: 'West Virginia', abbreviation: 'WV', id: 57 },
{ name: 'Wisconsin', abbreviation: 'WI', id: 58 },
{ name: 'Wyoming', abbreviation: 'WY', id: 59 }
];
const adjacentStates = {
1: [22, 29, 48, 13, 50, 37, 10, 17], // Alabama
2: [], // Alaska (does not border any state)
3: [], // American Samoa (not part of contiguous states)
4: [37, 43, 16, 33], // Arizona
5: [22, 29, 48, 13, 37, 17], // Arkansas
6: [37, 43, 4, 16], // California
7: [37, 16, 50, 38, 39], // Colorado
8: [26, 20], // Connecticut
9: [26, 45, 38], // Delaware
10: [37, 1, 38, 47, 25], // District of Columbia
11: [], // Federated States of Micronesia (not part of contiguous states)
12: [38, 1, 13, 47, 25], // Florida
13: [38, 1, 12, 37, 10, 47], // Georgia
14: [], // Guam (not part of contiguous states)
15: [], // Hawaii (not part of contiguous states)
16: [6, 4, 33, 32, 58, 19, 43], // Idaho
17: [26, 1, 38, 5, 13, 7, 8, 18, 45], // Illinois
18: [26, 17, 45], // Indiana
19: [58, 16, 28, 31, 43], // Iowa
20: [26, 8, 18], // Kansas
21: [26, 45, 18, 50, 48], // Kentucky
22: [5, 29, 48, 1], // Louisiana
23: [], // Maine (not part of contiguous states)
24: [], // Marshall Islands (not part of contiguous states)
25: [38, 1, 12, 10, 47], // Maryland
26: [8, 20, 45, 18, 17, 9], // Massachusetts
27: [18, 37], // Michigan
28: [31, 19, 58], // Minnesota
29: [5, 22, 48, 1], // Mississippi
30: [58, 31], // Missouri
31: [28, 30, 58, 16], // Montana
32: [7, 16, 52], // Nebraska
33: [6, 4, 43, 16], // Nevada
34: [26], // New Hampshire
35: [26, 45], // New Jersey
36: [37, 43, 4, 16, 33], // New Mexico
37: [6, 4, 16, 36, 43, 33, 12, 47, 13, 1, 38, 10, 38], // New York
38: [13, 1, 37, 10, 25, 12, 47, 50, 48, 39, 18, 45, 41], // North Carolina
39: [30, 38, 48], // North Dakota
40: [], // Northern Mariana Islands (not part of contiguous states)
41: [45, 18], // Ohio
42: [45, 33, 51, 36, 44], // Oklahoma
43: [6, 16, 33, 4, 19, 31], // Oregon
44: [], // Palau (not part of contiguous states)
45: [18, 41, 26, 9, 8, 12, 47, 21], // Pennsylvania
46: [], // Puerto Rico (not part of contiguous states)
47: [26, 10, 37, 12, 25, 13, 38, 1], // Rhode Island
48: [29, 5, 22, 1, 38, 38], // South Carolina
49: [30, 58, 39], // South Dakota
50: [1, 21, 38], // Tennessee
51: [36, 33, 42, 44], // Texas
52: [32], // Utah
53: [], // Vermont (not part of contiguous states)
54: [], // Virgin Islands (not part of contiguous states)
55: [38, 38, 45, 38], // Virginia
56: [43], // Washington
57: [45, 41], // West Virginia
58: [19, 31, 30, 27, 28], // Wisconsin
59: [31, 7, 16] // Wyoming
};
console.log(adjacentStates[1]); // Example of how to access adjacent states of Alabama by ID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment