Underscore Functional Programming
1. Introduction
In this assignment, you use the Underscore library https://underscorejs.org to program several functions to process the wsudgrs dataset found at this link:
https://xinghuizhao.github.io/wsudata/wsudgrs.js
2. Environment Setup
Follow the instructions below:
1. Set up JSfiddle with Underscore, use the latest version 1.8.3. This can be done by clicking on
to bring up drop down options. See the figure below.
Note you can NOT use loops or if statements in any of the
functions, otherwise you will lose points for them.
Homework #3 Due October 12th, 2020
2. To verify that Underscore is available in your JSfiddle, invoke an underscore function and log the output to the console.
For the function code, you can just use: console.log(_.identity(1));
Homework #3 Due October 12th, 2020
3. Load the Dataset
We will be using a dataset of graduate information about WSU over a 10 year sampling period extracted previously by Xinghui. It is stored in a js file located here:
https://xinghuizhao.github.io/wsudata/wsudgrs.js
This file defines "wsudgrs", which is an array of objects, each representing a data entry. The first couple of rows look like this:
{
"FISCAL_YEAR":2007,
"CAMPUS":"Pullman",
"Level":"Bachelors",
"AWARDS":3515
}, {
"FISCAL_YEAR":2008,
"CAMPUS":"Pullman",
"Level":"Bachelors",
"AWARDS":3481
}, {
"FISCAL_YEAR":2009,
"CAMPUS":"Pullman",
"Level":"Bachelors",
"AWARDS":3409
}
Homework #3 Due October 12th, 2020
To load this data into JSFiddle, you need to specify it as an "External Resource". Click on the "URL" on the left side of the window, enter https://xinghuizhao.github.io/wsudata/wsudgrs.js, and click the + icon to save it, see below:
To test that the dataset is defined correctly, try printing out its length to the console. You should get a length of 178.
Homework #3 Due October 12th, 2020
4. Data Processing
Using the Underscore library, implement the following functions to process the wsudgrs dataset:
1) totalDegrees(data): This function is passed a data structure like wsudgrs and returns the total number of degrees awarded in the data set.
2) percentagePhD(data): This function is passed a data structure like wsudgrs and returns the percentage of degrees that were awarded to PhD students. Such students are indicated by the string "Doctoral" in the "Level" field.
3) totalDegreesByYear(data, year): This function can be passed wsudgrs and a year and returns the total number of degrees awarded in that year.
4) listCampuses(data): This function can be passed wsudgrs and returns an array containing all the campuses referenced in the dataset.
5) listCampusDegrees(data): This function can be passed wsudgrs and returns an object where the property keys are campuses and the values are the number of degrees awarded by the campus.
6) maxDegrees(data): This function can be passed wsudgrs, computes the number of degrees earned in each year in the dataset, and then returns an integer which is the number of degrees earned in the year where the most degrees were earned.
For this assignment, adherence to the conventions of the functions in this document is required. Recall, no loops nor if statements may be used.
Homework #3 Due October 12th, 2020
5. Submission
This assignment is due at 11:59pm on 10/12/2020. Late work will be accepted up till 11:59pm on 10/15/2020 for a 20% mark down.
Submit you code as one file with your information (name, date, etc.) in comments at the top. Name it something relevant, like “HW3.js”.
6. Grading
Each Function is worth 5 points for a total of 30 points. Another 5 points will involve the readability and quality of the code.
5pts totalDegrees
5pts percentagePhD
5pts totalDegreesByYear
5pts listCampuses
5pts listCampusDegrees
5pts maxDegrees
5pts Code Quality/Readability
TOTAL: 35 pts




