There is no input to the printProfitData
function itself, but it does read from the data.csv
file, which is provided with the repo. The data.csv
has rows with headers labeled as follows and in the following order:
- Year
- Rank
- Company
- Revenue (in millions)
- Profit (in millions)
The printProfitData
function doesn't have any return values, but it does have 4 side effects:
- printing out the total number of rows of data (excluding the header) in
data.csv
- printing out the number of rows containing valid numeric profits
- printing out the top 20 entries ranked in order of highest profit
- generating a JSON file (
data2.json
) that contains all of the entries from the csv file that have valid profit numbers, ordered from highest profit to lowest profit
- the function,
printProfitData
is contained within the app.js file - it does the following:
- Reads the
data.csv
file - Prints the number of lines of data within the file (excluding the header)
- Iterates over each line from the file and reformats the data into an object
- Pushes objects with valid profit data into an array
- Prints the number of entries in
data.csv
with valid profit data - Writes the valid entries to a JSON file called
data2.json
, ordered from greatest profit to least profit(loss) - Prints out the top 20 entries with the highest profit
- Reads the
The tests are contained in the test.js
file, and test for the following:
- a JSON file is created when the printProfitData function is called
- that the function prints three answers
Node.js
- Clone repo from Github
- Run
npm install
to install dependencies - Run script with
bash run.sh
- To test, delete
data2.json
file (if one exists) and runnpm run test