UNB/ CS/ David Bremner/ teaching/ cs2613/ tests/ T2/ sample

Instructions

  1. This exam is individual, all answers must be your own work.

  2. Save your answers to a directory tests/quiz2 in your cs2613 git repository. Commit and push to https://vcs.cs.unb.ca before 10:20AM. If you have git problems, ask for help before the deadline.

  3. This exam is open book. You can use

    1. Local copies of Eloquent JavaScript, the NodeJS API, and the MDN.net JavaScript documentation which can can be found at

      https://www.cs.unb.ca/~bremner/teaching/cs2613/books

    2. Other parts of the course web site

    3. Your own notes and work from previous labs and assignments.

Questions

For this quiz you will write JavaScript function eval. This function is similar to the function of Assignment 3, except that it evaluates an array where the first element specifies the operator. For example, consider the following test:

test("+", (t) => assert.strictEqual(eval(['+', 6, 9]),15));

Passing

To get 6 marks (roughly a “C”), your solution must

const six_plus_nine = ['+', 6, 9];
const six_times_nine = ['*', 6, 9];
const compound1 = ['+', six_times_nine, six_plus_nine];
const compound2 = ['*', six_times_nine, compound1];
const compound3 = ['-', compound2, 3];
test("+", (t) => assert.strictEqual(eval(six_plus_nine),15));
test("compound1", (t) => assert.strictEqual(eval(compound1),69));
test("compound2", (t) => assert.strictEqual(eval(compound2),3726));
test("compound3", (t) => assert.strictEqual(eval(compound3),3723));

Full marks

To get full marks, your solution must

const plus_list = ['+', 6, 9, 10, 9, -1, -2, -3, -4];
const times_list = ['*', 6, 9, 9, 2];
const compound4 = ['+', plus_list , times_list, 7];
test("new +", (t) => assert.strictEqual(eval(plus_list),24));
test("new *", (t) => assert.strictEqual(eval(times_list),972));
test("compound4", (t) => assert.strictEqual(eval(compound4),1003));