forked from liammclennan/JavaScript-Koans
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabout_arrays.js
More file actions
45 lines (36 loc) · 1.65 KB
/
about_arrays.js
File metadata and controls
45 lines (36 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module("About Arrays (topics/about_arrays.js)");
test("array literal syntax and indexing", function() {
var favouriteThings = ["cellar door", 42, true]; // note that array elements do not have to be of the same type
equal(__, favouriteThings[0], 'what is in the first position of the array?');
equal(__, favouriteThings[1], 'what is in the second position of the array?');
equal(__, favouriteThings[2], 'what is in the third position of the array?');
});
test("array type", function() {
equal(__, typeof([]), 'what is the type of an array?');
});
test("length", function() {
var collection = ['a','b','c'];
equal(__, collection.length, 'what is the length of the collection array?');
});
test("splice", function() {
var daysOfWeek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
var workingWeek = daysOfWeek.splice(__, __);
var weekend = daysOfWeek;
deepEqual(workingWeek, ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'], 'what is the value of workingWeek?');
deepEqual(weekend, ['Saturday', 'Sunday'], 'what is the value of weekend?');
});
test("stack methods", function() {
var stack = [];
stack.push("first");
stack.push("second");
equal(__, stack.pop(), 'what will be the first value popped off the stack?');
equal(__, stack.pop(), 'what will be the second value popped off the stack?');
});
test("queue methods", function() {
var queue = [];
queue.push("first");
queue.push("second");
queue.unshift("third");
equal(__, queue.shift(), 'what will be shifted out first?');
equal(__, queue.shift(), 'what will be shifted out second?');
});