In this experience, you will explore functional programming concepts. Before starting, please go through the readings on Functional programming.
To make this experience more interesting and enjoyable, we’re going to use a Hawaii Open Dataset providing University of Hawaii Student Degrees Awarded. Here’s a screen image of this dataset:
I suggest you go to degrees awarded data preview and play around a little bit so you understand how the data is structured.
So that you can easily access the UH dataset, I’ve set up a web page at https://ics-software-engineering.github.io/uhdata/uhdataf24.ts that defines a variable called uhdata
whose value is an array of objects, one for each row in the table. Here’s what the first couple of rows look like:
type UhData = {
fiscalYear: number;
campus: string;
cip: number;
cipDesc: string;
group1: string;
group2: string;
group3: string;
group4: string;
group5: string;
outcome: string;
hawaiianLegacy: string;
awards: number;
};
const testData: UhData[] = [
{fiscalYear: 2023, campus: "UH Hilo", cip: 90101, cipDesc: "Speech Communicatn & Rhetoric", group1: "College of Arts & Sciences", group2: "Arts & Humanities", group3: "Communication", group4: "Communication", group5: "", outcome: "Bachelor's Degrees", hawaiianLegacy: "HAWAIIAN", awards: 16},
{fiscalYear: 2023, campus: "UH Manoa", cip: 130301, cipDesc: "Curriculum & Instruction", group1: "College of Education", group2: "Education", group3: "Curriculum Studies", group4: "Curriculum Studies", group5: "", outcome: "Master's Degrees",
hawaiianLegacy: "HAWAIIAN", awards: 20},
{fiscalYear: 2023, campus: "UH Manoa", cip: 140801, cipDesc: "Civil Engineering", group1: "College of Engineering", group2: "Engineering", group3: "Civil Engineering", group4: "", group5: "", outcome: "Master's Degrees", hawaiianLegacy: "", awards: 16},
];
Open TypeScript Playground. You may need to delete the existing code in the Playground. Then copy the https://ics-software-engineering.github.io/uhdata/uhdataf24.ts code into your TypeScript Playground to see the data structure.
To test that the uhdata
variable is defined correctly, try printing out its length to the console. You should get a length of 635.
Note: your solutions cannot use FOR or WHILE Loops!
Now that you have the UH degree data available in Playground, the fun begins!
Start your timer.
Create a variable called testdata
and set it equal to the example data above. Use this variable to check that your functions work correctly before running them on the full data set.
Use the methods provided by Typescript Array (see Array Methods ) to implement the following two functions. Note that your solutions cannot include a for loop or an if statement!
totalDegrees(data). This function is passed a data structure like uhdata
and returns the total number of degrees awarded in the data set. For the testdata
set, the correct answer is 52. For the uhdata
set, the correct answer is 7380.
percentageHawaiian(data). This function can be passed uhdata
and returns the percentage of degrees that were awarded to students of Hawaiian Legacy in the dataset. Such students are indicated by the string “HAWAIIAN” in the “HAWAIIAN_LEGACY” field. For the testdata
set, correct answer is about 69.2%. For the uhdata
set, correct answer is about 25.9%.
Press the “Share” button to create a URL to refer to your code.
Stop your timer and record your time. Be sure to record it, because you will need your WOD time data when you write your technical essay.
Rx: < 17 min Av: 17 - 25 min Sd: 25 - 30 min DNF: 30+ min
Once you’ve finished trying the WOD for the first time, watch me do it (Note: the screencast below has not been updated to use Typescript but the functional programming is similar and you do not need underscore.js).
You’ll learn significantly less from watching me solve the if you haven’t attempted the WOD yourself first.
While it’s an achievement to finish the WOD no matter how long it takes, you might experience “diminishing returns” if you work longer than the DNF time. Thus, it is usually strategic to stop working at the DNF time and watch my solution.
After watching my solution, I recommend that you repeat the WOD if you have not achieved at least Av performance. If so, be sure to:
Feel free to keep trying until you make Rx if that’s of interest to you.
By the time and date indicated on the Schedule page, submit this assignment via Laulima.
Your submission should contain:
A link to the Typescript Playground. Make sure you include the complete URL so that I can open it in my browser.
The number of times you have attempted this assignment so far, and for each time, how long it took you.
A brief sentence telling us if you used ChatGPT or GitHub Copilot. If you used neither, then tell us that.
You will receive full credit for this practice WOD as long as you have attempted it at least once and submitted your work on Laulima with all required data before the due date. Your code does not have to run perfectly for you to receive full credit.