-
Notifications
You must be signed in to change notification settings - Fork 32
/
arrays.test.js
178 lines (145 loc) · 4.85 KB
/
arrays.test.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
let hotPeppers = [
'Madame Jeanette',
'Scotch Bonnet',
'White Habanero',
'Habanero',
'Fatalii',
'Devil’s Tongue',
'Tigerpaw',
'Chocolate Habanero (aka Congo Black)',
'Caribbean Red Habanero',
'Red Savina',
'Naga Morich (aka Dorset Naga)',
'Trinidad Scorpion CARDI',
'Bhut Jolokia Chocolate',
'Bhut Jolokia (aka Ghost Pepper)',
'7 Pot Chili ',
'Gibraltar (aka Spanish Naga)',
'Infinity Chili',
'Naga Viper',
'7 Pod Douglah (aka Chocolate 7 Pot)',
'Trinidad Scorpion Butch T',
'Trinidad Moruga Scorpion',
'Carolina Reaper'
];
describe('DAY 4: Test Arrays', () => {
it('Array to be instance of Array (literal)', () => {
// use literal notation
let array;
expect(array).toBeInstanceOf(Array);
});
it('Array to be instance of Array (constructor)', () => {
// use constructor
let array;
expect(array).toBeInstanceOf(Array);
});
it('Array to be instance of Object and Array', () => {
// use any of the previous
let array;
expect(array).toBeInstanceOf(Array);
expect(array).toBeInstanceOf(Object);
});
it('Initialize Array with length of 4 (literal)', () => {
// use literal
let array;
expect(array.length).toBe(4);
});
it('Initialize Array with length of 4 (constructor)', () => {
// use constructor
let array;
expect(array.length).toBe(4);
});
it('Initialize Array with length of 1 (constructor), and first entry value to be 4', () => {
// use constructor
let array;
expect(array.length).toBe(1);
expect(array[0]).toBe(4);
});
it('Mutate Array length to be 4', () => {
let array = [];
// use a mutator method to add elements
expect(array.length).toBe(4);
});
it('Mutate Array length to be 5', () => {
let array = [42, 42, 42, 42, 42, 42];
// use a mutator method to remove elements
expect(array.length).toBe(5);
});
it('Remove the first element of the array', () => {
let array = ['a', 'b', 'c', 'd'];
// use a method to remove it
expect(array.indexOf('a')).toBe(-1);
});
it('Remove the last element of the array', () => {
let array = ['a', 'b', 'c', 'd'];
// use a method to remove it
expect(array.indexOf('d')).toBe(-1);
});
it('Remove an element off from inner boundaries of the array', () => {
let array = ['a', 'b', 'c', 'd'];
// use a method to remove it
expect(array.indexOf('b')).toBe(-1);
});
it('Create a new array containing the values of 2 different arrays (method)', () => {
let array1 = ['a', 'b', 'c', 'd'];
let array2 = [1, 2, 3, 4, 5];
// use a method to create it
let array3;
expect(array3).toEqual([1, 2, 3, 4, 5, 'a', 'b', 'c', 'd']);
});
it('Create a new array containing the values of 2 different arrays (operator)', () => {
let array1 = ['a', 'b', 'c', 'd'];
let array2 = [1, 2, 3, 4, 5];
// use an operator to create it
let array3;
expect(array3).toEqual(['a', 'b', 'c', 'd', 1, 2, 3, 4, 5]);
});
it('Create a string from an array (method)', () => {
let array = ['a', 'b', 'c', 'd'];
// use a method to create it
let string;
expect(string).toBe('a-b-c-d');
});
it('Create an array from a string (method)', () => {
let string = 'a-b-c-d';
// use a method to create it
let array;
expect(array).toEqual(['a', 'b', 'c', 'd']);
});
it('Create an array from a string (operator)', () => {
let string = 'abcd';
// use an operator to create it
let array;
expect(array).toEqual(['a', 'b', 'c', 'd']);
});
it('Reverse the a string using the learned techniques', () => {
let string = 'abcd';
// use available method for strings an arrays
let reversed;
expect(reversed).toEqual('dcba');
});
it('Copy the values of array a to array b using an iteration', () => {
let a = [1, 2, 'a', 'b', 'c', [6, 7]];
let b = [];
/**
*
* iterate over a ( you can use an iteration statement or an array method )
* validate each value has been correctly copied
*
*/
//! add your code here
// ? why a IS NOT b? explain
expect(a).not.toBe(b);
// ? but IS EQUAL to b? explain
expect(a).toEqual(b);
// ? then why a[5] ACTUALLY IS b[5]
expect(a[5]).toBe(b[5]);
});
it('Find an element by value using an array method', () => {
let array = hotPeppers;
let myFavorite = 'Habanero';
// use an array method
let found;
expect(found).toBe(myFavorite);
});
});