You are tasked with converting a csv into a markdown file. Reading in US Census data which contains the population for a 1000 cities, grouping the data by Region and State.
- Not allowed to use
for
loops. - Avoid using the
foreach
method
In order to get familiar with using Array methods, the only rule is that you are not allowed to use traditional for
loops. The more you use Array methods like .reduce
and .filter
instead of .forEach
the better.
You have a couple of utility functions provided for you
Will read in and parse the given file. Returning something that looks like this
[{
Region:"Northeast",
State:"New York",
City:"New York, NY",
Population:"8622698",
}, ... ]
Creates the markdown file at the specified location, expecting regions
to be in a format like this:
[{
name: 'Northeast',
states:[{
name: 'New York',
cities:[{
name: 'New York, NY',
population: 8622698
}]
}]
}]
To help with debugging, will console.log
an object after passing it through beautify
- Open the terminal
- Navigate to your Documents folder then run the following to clone the repository
git clone https://github.com/byuitechops/city-organizer.git
cd city-organizer
npm i
- Open the created folder in vscode
- Install the Markdown Preview plugin in vscode to see how your output will be rendered
- Write some awesome code
- Run your code by running
node main.js
in the console - To run the test cases install jest globaly with
npm install -g jest
Testing: run jest create.test.js
Outcome: Be comfortable with using array methods to manipulate data into different formats
In main.js
add the nessesary code to transform the flat csv data into the nested format that the write
function is expecting. If everything goes good the write
function should create a file that looks like this:
# Midwest
## Illinois
- Chicago, IL ( `pop. 2,716,450` )
# Mountain
## Arizona
- Phoenix, AZ ( `pop. 1,626,078` )
# Northeast
## New York
- New York, NY ( `pop. 8,622,698` )
## Pennsylvania
- Philadelphia, PA ( `pop. 1,580,863` )
# Pacific
## California
- San Jose, CA ( `pop. 1,035,317` )
- San Diego, CA ( `pop. 1,419,516` )
- Los Angeles, CA ( `pop. 3,999,759` )
# South
## Texas
- Dallas, TX ( `pop. 1,341,075` )
- San Antonio, TX ( `pop. 1,511,946` )
- Houston, TX ( `pop. 2,312,717` )
Testing: run jest sort.test.js
Outcome: Become comfortable with using the sort
function with multiple different data formats and targets
Complete the following sorting challenges
Either add code or change your existing code so that states under a REGION are sorted alphabetically
# Pacific
## California
- Oxnard, CA ( `pop. 210,037` )
## Oregon
- Portland, OR ( `pop. 647,805` )
## Washington
- Tacoma, WA ( `pop. 213,418` )
- Spokane, WA ( `pop. 217,108` )
- Seattle, WA ( `pop. 724,745` )
# Mountain
## Colorado
- Aurora, CO ( `pop. 366,623` )
- Colorado Springs, CO ( `pop. 464,474` )
- Denver, CO ( `pop. 704,621` )
## Idaho
- Boise City, ID ( `pop. 226,570` )
## Nevada
- North Las Vegas, NV ( `pop. 242,975` )
- Reno, NV ( `pop. 248,853` )
- Henderson, NV ( `pop. 302,539` )
- Las Vegas, NV ( `pop. 641,676` )
Either add code or change your existing code so that cities under a STATE are sorted by their population
# Pacific
## California
- Los Angeles, CA ( `pop. 3,999,759` )
- San Diego, CA ( `pop. 1,419,516` )
- San Jose, CA ( `pop. 1,035,317` )
- San Francisco, CA ( `pop. 884,363` )
- Fresno, CA ( `pop. 527,438` )
- Sacramento, CA ( `pop. 501,901` )
- Long Beach, CA ( `pop. 469,450` )
- Oakland, CA ( `pop. 425,195` )
- Bakersfield, CA ( `pop. 380,874` )
- Anaheim, CA ( `pop. 352,497` )
- Santa Ana, CA ( `pop. 334,136` )
- Riverside, CA ( `pop. 327,728` )
- Stockton, CA ( `pop. 310,496` )
- Irvine, CA ( `pop. 277,453` )
- Chula Vista, CA ( `pop. 270,471` )
- Fremont, CA ( `pop. 234,962` )
- San Bernardino, CA ( `pop. 216,995` )
- Modesto, CA ( `pop. 214,221` )
- Fontana, CA ( `pop. 211,815` )
- Santa Clarita, CA ( `pop. 210,888` )
- Oxnard, CA ( `pop. 210,037` )
Either add code or change your existing code so that the regions are in order of West to East. So they follow as Pacific, Mountain, Midwest, South, Northeast
,
# Pacific
## California
- Los Angeles, CA ( `pop. 3,999,759` )
- San Diego, CA ( `pop. 1,419,516` )
- San Jose, CA ( `pop. 1,035,317` )
# Mountain
## Arizona
- Phoenix, AZ ( `pop. 1,626,078` )
# Midwest
## Illinois
- Chicago, IL ( `pop. 2,716,450` )
# South
## Texas
- Houston, TX ( `pop. 2,312,717` )
- San Antonio, TX ( `pop. 1,511,946` )
- Dallas, TX ( `pop. 1,341,075` )
# Northeast
## New York
- New York, NY ( `pop. 8,622,698` )
## Pennsylvania
- Philadelphia, PA ( `pop. 1,580,863` )
Testing: run jest unique.test.js
Outcome: Become better at noticing your assumptions
Use the nonunique.csv
csv instead of cities.csv
. The only thing that has changed is that city names no longer contain the state name acronym. So there are now 5 cities with the name Springfield
all in different states. Just making sure that you are not relying on the state names to be unique.
Testing: run jest write.test.js
Outcome: Become more comfortable with researching documentation
Research how to use fs.writeFileSync, fs.readFileSync and d3.csvParse to read, write, and parse the CSV. You are not allowed to use the provided utils
functions in this challenge. You will need to read the csv and write to the file on your own, with the fs
and d3-dsv
libraries.
Using the sorts from the previous challenge. Write out just the first 10 rows to the output.md
file. That file will be checked that it matches this output exactly.
# Pacific
## California
- Los Angeles, CA `pop. 3999759`
- San Diego, CA `pop. 1419516`
- San Jose, CA `pop. 1035317`
# Mountain
## Arizona
- Phoenix, AZ `pop. 1626078`
# Midwest
## Illinois
- Chicago, IL `pop. 2716450`
# South
## Texas
- Houston, TX `pop. 2312717`
- San Antonio, TX `pop. 1511946`
- Dallas, TX `pop. 1341075`
# Northeast
## New York
- New York, NY `pop. 8622698`
## Pennsylvania
- Philadelphia, PA `pop. 1580863`
Testing: run jest sum.test.js
Outcome: Become better at designing code that has taken into account things that might need to be accessable in the future.
Add the population
property to Region and States, which contains the sum of the populations beneath them.
[{
name: 'Northeast',
population: 8622698
states:[{
name: 'New York',
population: 8622698
cities:[{
name: 'New York, NY',
population: 8622698
}]
}]
}]
Testing: run jest optimize.test.js
Outcome: Become more aware of the costs that come from a specific implementation
Run your code against all.csv
to see how long it takes. It contains almost 8,500 cities across america.