Sep. 30 - Oct. 2
In lecture we introduced the push method of an Array, allowing us to add data onto an existing array. In lab, you will go through a problem very similar to what you saw in lecture.
To get started, first download the ZIP file for Lab 5 here.
Last year the following comic from xkcd.com went viral when it was brutally cold for several days in a row in the midwest:
Ignoring any larger implications made by the comic, lets look at the data by doing the data analysis ourselves!
We have already provided for you input data for this lab, which will come to you in the following format:
[ { year: 2015, lows: [ 32, 19, 30, 23, ... ] }, { year: 2014, lows: [ 8, 21, 18, 24, ... ] }, ... ]
That is, the input is an Array where each element is an Object that has two variables:
year
, the year of the data (a Number)lows
, an Array of Numbers containing the low temperatures for each day in the yearTo complete this lab, your function must return an Array of Objects:
[ { year: 2015, zeroDegreeDays: 3 }, { year: 2014, zeroDegreeDays: 14 }, { year: 2014, zeroDegreeDays: 0 }, ... ]
That is, the return value is an Array where each element is an Object that has two variables:
year
, the year of the data (a Number), the same as the inputzeroDegreeDays
, the number of days in the year that the temperature never reaches zero degrees (a Number)
As part of completing this lab, you will need to process the lows
that come as part of the input data.
As a reminder, this array will be an array of low temperatures and have the following format:
[ 32, 19, 30, 23, ... ]
Complete the findZeroDegreeDays
function in lab5.js so that the function returns the number of days where the
low temperature was below zero (0) degrees. This is very similar to the function you wrote in last week and
requires one for-loop and one if-statement.
We have included test cases that test only Part 3. Make sure that the Lab webpage indicates to you that Part 3 works before going forward! You will be using the function you created in Part 3 to finish Part 4.
Inside of lab5.js you will find a second function: analyzeWeather
.
To successfully complete this function, you will need to:
findZeroDegreeDays
function with the array of low temperatures. This function will
return the zero degree days (a Number) that you will need to use later.
year
and
zeroDegreeDays
. This is exactly like what we did in lecture on Wednesday!
.push
function
you saw in lecture on Wednesday to push the newly created object onto an array to be returned after
you have finished processing each piece of data.
To submit your lab, you must submit your lab5.js to the CS 105 website. You should submit ONLY .js file. You do not need to submit the other files in the folder. Click here to submit the lab!