Starting from:

$25

CS320 - Underscore Functional Programming - Homework 3 - Solved

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

Note you can NOT use loops or if statements in any of the 
functions, otherwise you will lose points for them.
 
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.

 

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));

 

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

  }

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.

 

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.

More products