-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathabout_arrays.js
More file actions
73 lines (64 loc) · 1.76 KB
/
Copy pathabout_arrays.js
File metadata and controls
73 lines (64 loc) · 1.76 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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(
'cellar door',
favouriteThings[0],
'what is in the first position of the array?',
);
equal(42, favouriteThings[1], 'what is in the second position of the array?');
equal(
true,
favouriteThings[2],
'what is in the third position of the array?',
);
});
test('array type', function () {
equal('object', typeof [], 'what is the type of an array?');
});
test('length', function () {
var collection = ['a', 'b', 'c'];
equal(3, 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(0, 5);
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(
'second',
stack.pop(),
'what will be the first value popped off the stack?',
);
equal(
'first',
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('third', queue.shift(), 'what will be shifted out first?');
equal('first', queue.shift(), 'what will be shifted out second?');
});