Take home Quiz CMSC 198J
Due Wednesday Jan 19, 11:00 pm Winter 2011

Objective

To practice functions and arrays.

Specifications

You must implement the functions described below which are used by the Driver.html program. Place the code for the functions in the file code.js that we have provided. The Driver.html file already includes code.js (we have done this for you). Just write the functions (no need to put HTML or script tags surrounding the functions) in code.js. To download these files right-click on the above links. The Driver.html program will generate the following output:

***Test 1
10,10,10
10,10,10
***Test 2
Not Ragged Array
***Test 3
Arrays are equal
***Test 4
6000,900 

Functions

  1. Write a function named “initialize” that has the following prototype:

    function initialize(initialValue, maxRows, maxCols);

    The function creates a two-dimensional array of integers with a number of rows and columns that corresponds to maxRows, and maxCols, respectively. In addition, the function initializes each array entry with the value initialValue.

  2. Write a function named “isRagged” that determines whether a two-dimensional array is a ragged array. Remember, a ragged array is one where all the rows do not have the same length.

  3. Write a function named “equals” that has the following prototype:

    function equals(array1, array2);

    The function will return true if the two-dimensional arrays (array1 and array2) have the same corresponding elements. For example:
            
            10, 20, 30       equals to           10, 20, 30
            50, 40                               50, 40 
    
            10, 30, 20       not equals to       10, 20, 30
            50, 40, 60                           40, 50, 60 
    
            10, 20, 30       not equals to       10, 20, 30
            40, 50, 60                           40, 50
        

  4. Write a function named “sum” that has the following prototype:

    function sum(array1);

    The function takes a two-dimensional array of integers (array1) as parameter and returns a one-dimensional array where each entry of the one-dimensional array corresponds to the sum of the values of each row of array1. For example if array1 is:
            10, 20, 30
            50, 40
            60, 9
    
            sum will return
    
            60, 90, 69
        

Requirements


Submission

Put the code.js file (only that file, we don't need Driver.html) in a folder named takeHome, zip the folder, and submit the zipped file using the submit server available.  After submitting your project make sure you download the submitted file and verify that what you have submitted is correct. Do not confuse the entry you have to use with the entry for Project #3 or Project #4. You will lose points if you do so. Please do not e-mail your project.

Academic Integrity

Please make sure you read the academic integrity section of the syllabus so you understand what is permissible in our programming projects. We want to remind you that we check your project against other students' projects and any case of academic dishonesty will be referred to the Office of Student Conduct.

Web Accessibility