Skip to content

Commit 3da9703

Browse files
committed
Finished the 45th koan with comments
1 parent 05d64a3 commit 3da9703

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

topics/about_arrays.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,49 @@
11
module("About Arrays (topics/about_arrays.js)");
22

3+
//Question 40 asks about arrays where multiple values are stored in one variables//
34
test("array literal syntax and indexing", function() {
45
var favouriteThings = ["cellar door", 42, true]; // note that array elements do not have to be of the same type
5-
equal(__, favouriteThings[0], 'what is in the first position of the array?');
6-
equal(__, favouriteThings[1], 'what is in the second position of the array?');
7-
equal(__, favouriteThings[2], 'what is in the third position of the array?');
6+
equal("cellar door", favouriteThings[0], 'what is in the first position of the array?');
7+
equal(42, favouriteThings[1], 'what is in the second position of the array?');
8+
equal(true, favouriteThings[2], 'what is in the third position of the array?');
89
});
910

11+
//Question 41 asks what is the type of an array using the typeof function. An array is an [object]//
1012
test("array type", function() {
11-
equal(__, typeof([]), 'what is the type of an array?');
13+
equal("object", typeof([]), 'what is the type of an array?');
1214
});
1315

16+
//Question 42 asks what the amount of values in the variable collection which is [3]//
1417
test("length", function() {
1518
var collection = ['a','b','c'];
16-
equal(__, collection.length, 'what is the length of the collection array?');
19+
equal(3, collection.length, 'what is the length of the collection array?');
1720
});
1821

22+
//Question 43 asks about the .splice function. This function adds or removes a value from original array by .splice('position of value', 'number of spots after to remove', 'added values') So varABC=(A, B, C) with a .splice(1,1) means to remove 1 item after the first position so output will be B, since B is removed. When accessing varABC again the output for that will now be A and C. So the var workingWeek is the spliced items Saturday and Sunday and new output for daysofWeek is Monday thru Friday. //
1923
test("splice", function() {
2024
var daysOfWeek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
21-
var workingWeek = daysOfWeek.splice(__, __);
22-
ok(workingWeek.equalTo([__]), 'what is the value of workingWeek?');
23-
ok(daysOfWeek.equalTo([__]), 'what is the value of daysOfWeek?');
25+
var workingWeek = daysOfWeek.splice(5, 2);
26+
ok(workingWeek.equalTo(['Saturday', 'Sunday']), 'what is the value of workingWeek?');
27+
ok(daysOfWeek.equalTo(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']), 'what is the value of daysOfWeek?');
2428
});
2529

30+
//Question 44 talks about the .push and.pop functions. The push functions adds an item to the end of the array. The pop function removes an item starting from the end of the array.//
2631
test("stack methods", function() {
2732
var stack = [];
2833
stack.push("first");
2934
stack.push("second");
3035

31-
equal(__, stack.pop(), 'what will be the first value popped off the stack?');
32-
equal(__, stack.pop(), 'what will be the second value popped off the stack?');
36+
equal("second", stack.pop(), 'what will be the first value popped off the stack?');
37+
equal("first", stack.pop(), 'what will be the second value popped off the stack?');
3338
});
3439

40+
//Question 45 talks about unshift. They are just like .push but start from the beginning of the array. So in this example since unshift is done after the first two functions, whatever is the value will show up first in the array. Shift is the same as .pop but for the beginning of the array.//
3541
test("queue methods", function() {
3642
var queue = [];
3743
queue.push("first");
3844
queue.push("second");
3945
queue.unshift("third");
4046

41-
equal(__, queue.shift(), 'what will be shifted out first?');
42-
equal(__, queue.shift(), 'what will be shifted out second?');
47+
equal("third", queue.shift(), 'what will be shifted out first?');
48+
equal("first", queue.shift(), 'what will be shifted out second?');
4349
});

0 commit comments

Comments
 (0)