Skip to content
Binary file added .DS_Store
Binary file not shown.
51 changes: 46 additions & 5 deletions module-exercises/arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,39 @@ evaluate(example_garbageCollectingArrays);

function passTheAssertions1() {
; // declare and assign a1
let a1 = [];
; // declare and assign a2
let a2 = a1;

console.assert(a1 === a2, 'a1 should strictly equal a2');


; // declare and assign b1
let b1 = [];
; // declare and assign b2
console.assert(b1 !== b2, 'b1 should not strictly equal b2');
let b2 = [];

console.assert(b1 !== b2, 'b1 should not strictly equal b2');


// ---

; // write one line to pass the assertions
a1 = a2 = ['hi!'];

console.assert(a1[0] === a2[0], 'a1[0] should strictly equal a2[0]');
console.assert(a1[0] === 'hi!', 'a1.x should strictly equal "hi!"');



; // write two lines to pass the assertions
;

b1 = ['bye!'];
b2 = b1;
console.assert(b1[0] === b2[0], 'b1[0] should strictly equal b2[0]');
console.assert(b1[0] === 'bye!', 'b1.x should strictly equal "bye!"');


}
evaluate(passTheAssertions1);

Expand All @@ -128,31 +144,51 @@ function passTheAssertions2() {
let reference1 = [];

; // write this line

let value2 = value1;

console.assert(value2 === value1, "value1 should strictly equal value2");

; // write this line

let reference2 = reference1;

console.assert(reference2 === reference1, "reference1 should strictly equal reference2");

value2 = value2 + 1; // write this line
value2 = value2 + 1; value1 = '___';


console.assert(value1 !== null, "value1 should strictly equal ___");

; // write this line
referans1[0] = reference2[0];
reference1 [0] = ['hi!'];
console.log(reference2);

console.assert(reference1[0] === reference2[0], "references[0] should be strictly equal");
console.assert(reference1[0] === 'hi!', "reference1[0] should be strictly equal to 'hi!'");

; // write this line
reference1 = reference2;

console.assert(reference1 === reference2, "references should be strictly equal");

// remove the array from memory
; // write this line
; // write this line
; reference1 = null;
; reference2 = null;
}
evaluate(passTheAssertions2);


function passTheAssertions3() {
; // write this line
; // write this line
arr1 = [];
arr2 = [];
arr1[1] = arr2[1];
arr[1] = ['B']


console.assert(arr1 !== arr2, 'the variables should not be strictly equal');
console.assert(arr1[1] === arr2[1], 'their first entries should be the same');
console.assert(arr1[1] === 'B', 'arr1[1]] should be "B"');
Expand All @@ -163,10 +199,15 @@ function passTheAssertions3() {

; // write this line
; // write this line
arr1[arr2[2]] = ['B'];
arr1[arr2[2]] = arr2[arr1[2]];

console.assert(arr1[arr2[2]] === 'B', 'arr2[2] should be "B"s index in arr1');
console.assert(arr1[arr2[2]] === arr2[arr1[2]], 'some tricky nested thing should be true');

; // write this line


console.assert(arr1 !== arr2, 'arr1 should strictly equal arr2');
console.assert(arr3 !== arr1, 'arr3 should not strictly equal arr`');
console.assert(arr3 === arr2, 'arr3 should strictly equal arr2');
Expand Down
32 changes: 16 additions & 16 deletions module-exercises/explicit-coercion.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
// fix the test cases' expected values to pass the function
const StringTests = [
// string values remain unchanged
{ name: 'str, any string', args: ['any string'], expected: null },
{ name: 'str, any string', args: ['any string'], expected: 'any string' },
// casting with String just puts quotes around a thing
{ name: 'num, 3', args: [3], expected: null },
{ name: 'boo, true', args: [true], expected: null },
{ name: 'obj, null', args: [null], expected: null },
{ name: 'und, undefined', args: [undefined], expected: null },
{ name: 'num, 3', args: [3], expected: '3' },
{ name: 'boo, true', args: [true], expected: 'true' },
{ name: 'obj, null', args: [null], expected: 'null' },
{ name: 'und, undefined', args: [undefined], expected: 'undefined' },
// write at least 5 more test cases for the String function
];
String.quizzing = true;
Expand All @@ -45,11 +45,11 @@ const NumberTests = [
{ name: 'num, Infinity', args: [Infinity], expected: Infinity },
{ name: 'num, NaN', args: [NaN], expected: NaN },
// true and false, the only boolean values
{ name: 'boo, true', args: [true], expected: 0 },
{ name: 'boo, false', args: [false], expected: 1 },
{ name: 'boo, true', args: [true], expected: 1 },
{ name: 'boo, false', args: [false], expected: 0 },
// null & undefined
{ name: 'obj, null', args: [null], expected: NaN },
{ name: 'und, undefined', args: [undefined], expected: 0 },
{ name: 'obj, null', args: [null], expected: 0 },
{ name: 'und, undefined', args: [undefined], expected: NaN },
// strings are bit more interesting, write 7 more test cases with string args
{ name: 'str, undefined', args: ['undefined'], expected: NaN },
{ name: 'str, Infinity', args: ['Infinity'], expected: Infinity },
Expand All @@ -68,19 +68,19 @@ const BooleanTests = [
{ name: 'boo, false', args: [false], expected: false },
// anything but 0 & NaN is cast to true
{ name: 'num, 3', args: [3], expected: true },
{ name: 'num, 0', args: [0], expected: true },
{ name: 'num, 0', args: [0], expected: false },
{ name: 'num, 1e3', args: [1000], expected: true },
{ name: 'num, Infinity', args: [Infinity], expected: false },
{ name: 'num, Infinity', args: [Infinity], expected: true },
{ name: 'num, NaN', args: [NaN], expected: false },
// null & undefined
{ name: 'obj, null', args: [null], expected: true },
{ name: 'und, undefined', args: [undefined], expected: true },
{ name: 'obj, null', args: [null], expected: false },
{ name: 'und, undefined', args: [undefined], expected: false },
// anything but an empty string is cast to true
{ name: 'str, undefined', args: ['undefined'], expected: false },
{ name: 'str, false', args: ['false'], expected: false },
{ name: 'str, undefined', args: ['undefined'], expected: true },
{ name: 'str, false', args: ['false'], expected: true },
{ name: 'str, Infinity', args: ['Infinity'], expected: true },
{ name: 'str, three', args: ['three'], expected: true },
{ name: 'str, ', args: [''], expected: true },
{ name: 'str, ', args: [''], expected: false },
{ name: 'str, 3', args: ['3'], expected: true },
];
Boolean.quizzing = true;
Expand Down
Loading