Last active
March 20, 2020 23:22
-
-
Save awong-dev/43c88318b95da1d661de062e971c8b3c to your computer and use it in GitHub Desktop.
Revisions
-
awong-dev revised this gist
Mar 20, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,7 +23,7 @@ function toDataByLocation(data) { } const entry_obj = {}; headers.forEach( (value, index) => { if (entry[index] !== undefined) { entry_obj[value] = entry[index] } else { entry_obj[value] = "" -
awong-dev revised this gist
Mar 20, 2020 . No changes.There are no files selected for viewing
-
awong-dev created this gist
Mar 20, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ function toDataByLocation(data) { const headers = data.values[0]; const approvedIndex = headers.findIndex( e => e === 'Approved' ); const stateIndex = headers.findIndex( e => e === 'State?' ); const cityIndex = headers.findIndex( e => e === 'City' ); const data_by_location = {}; const published_entries = data.values.slice(1).filter((entry) => entry[approvedIndex] === "x"); published_entries.forEach( entry => { const state = entry[stateIndex]; const city = entry[cityIndex]; let entry_array; if (!(state in data_by_location) || !(city in data_by_location[state])) { entry_array = []; if (state in data_by_location) { data_by_location[state][city] = entry_array; } else { data_by_location[state] = { [city]: entry_array }; } } else { entry_array = data_by_location[state][city]; } const entry_obj = {}; headers.forEach( (value, index) => { if (entry_obj[index] !== undefined) { entry_obj[value] = entry[index] } else { entry_obj[value] = "" } }); entry_array.push(entry_obj); }); return data_by_location; }