1 | 1 | 'use strict'; |
2 | | |
3 | 1 | var dump = require('./zip_dump.json'); |
4 | | |
5 | | // ----- get zip codes in state with lat/long info |
6 | | // -- @param state {String} shortcode for US state / territory |
7 | | // -- @return {Array} of objects (zip codes w/ coordinates in state) |
8 | | // --------------------------------------- |
9 | 1 | module.exports = function(state) { |
10 | | |
11 | | // get zip codes in given state |
12 | 1 | var zipsInState = []; |
13 | | |
14 | 1 | for (var i = 0; i < dump.length; i++) { |
15 | | |
16 | 43191 | if (dump[i].state === state) { |
17 | 232 | zipsInState.push(dump[i]); |
18 | | } |
19 | | |
20 | | } |
21 | | |
22 | | // format zip codes |
23 | 1 | var formattedZips = []; |
24 | | |
25 | 1 | for (var j = 0; j < zipsInState.length; j++) { |
26 | | |
27 | 232 | var current = { |
28 | | latitude: parseFloat(zipsInState[j].latitude), |
29 | | longitude: parseFloat(zipsInState[j].longitude), |
30 | | cityState: zipsInState[j].city + ', ' + zipsInState[j].state, |
31 | | zip: zipsInState[j].zip |
32 | | }; |
33 | | |
34 | 232 | formattedZips.push(current); |
35 | | |
36 | | } |
37 | | |
38 | 1 | return formattedZips; |
39 | | |
40 | | }; |