2
2
maxOfTwoNumbers,
3
3
findLongestWord,
4
4
sumNumbers,
5
+ sum,
5
6
averageNumbers,
6
7
uniquifyArray,
7
8
doesWordExist,
@@ -24,44 +25,44 @@ const shuffle = (currentArray) => {
24
25
} ;
25
26
26
27
describe ( 'Find the maximum' , ( ) => {
27
- it ( 'should declare a function named maxOfTwoNumbers' , ( ) => {
28
+ test ( 'should declare a function named maxOfTwoNumbers' , ( ) => {
28
29
expect ( typeof maxOfTwoNumbers ) . toBe ( 'function' ) ;
29
30
} ) ;
30
31
31
- it ( 'should return greater of two arguments - if the first argument greater' , ( ) => {
32
+ test ( 'should return greater of two arguments - if the first argument greater' , ( ) => {
32
33
expect ( maxOfTwoNumbers ( 2 , 1 ) ) . toBe ( 2 ) ;
33
34
expect ( maxOfTwoNumbers ( 5 , - 7 ) ) . toBe ( 5 ) ;
34
35
} ) ;
35
36
36
- it ( 'should return greater of two arguments - if the second argument greater' , ( ) => {
37
+ test ( 'should return greater of two arguments - if the second argument greater' , ( ) => {
37
38
expect ( maxOfTwoNumbers ( 1 , 3 ) ) . toBe ( 3 ) ;
38
39
expect ( maxOfTwoNumbers ( - 5 , 3 ) ) . toBe ( 3 ) ;
39
40
} ) ;
40
41
41
- it ( 'should return either arguments - if both arguments are equal' , ( ) => {
42
+ test ( 'should return either arguments - if both arguments are equal' , ( ) => {
42
43
expect ( maxOfTwoNumbers ( 4 , 4 ) ) . toBe ( 4 ) ;
43
44
} ) ;
44
45
} ) ;
45
46
46
47
describe ( 'Find the longest word' , ( ) => {
47
- it ( 'should declare a function named findLongestWord' , ( ) => {
48
+ test ( 'should declare a function named findLongestWord' , ( ) => {
48
49
expect ( typeof findLongestWord ) . toBe ( 'function' ) ;
49
50
} ) ;
50
51
51
- it ( 'should return null when called with an empty array' , ( ) => {
52
+ test ( 'should return null when called with an empty array' , ( ) => {
52
53
expect ( findLongestWord ( [ ] ) ) . toBe ( null ) ;
53
54
} ) ;
54
55
55
- it ( 'should return the word when called with a single-word array' , ( ) => {
56
+ test ( 'should return the word when called with a single-word array' , ( ) => {
56
57
expect ( findLongestWord ( [ 'foo' ] ) ) . toBe ( 'foo' ) ;
57
58
} ) ;
58
59
59
- it ( 'should return the first occurrence of the word when longest have multiple occurrences ' , ( ) => {
60
+ test ( 'should return the first occurrence of the word when longest have multiple occurrences ' , ( ) => {
60
61
expect ( findLongestWord ( [ 'foo' , 'bar' ] ) ) . toBe ( 'foo' ) ;
61
62
expect ( findLongestWord ( [ 'bar' , 'foo' ] ) ) . toBe ( 'bar' ) ;
62
63
} ) ;
63
64
64
- it ( 'should return the longest occurrence when it has multiple words' , ( ) => {
65
+ test ( 'should return the longest occurrence when it has multiple words' , ( ) => {
65
66
let words = [ 'a' , 'zab' , '12abc' , '$$abcd' , 'abcde' , 'ironhack' ] ;
66
67
for ( let i = 0 ; i < 10 ; i ++ ) {
67
68
words = shuffle ( words ) ;
@@ -71,120 +72,120 @@ describe('Find the longest word', () => {
71
72
} ) ;
72
73
73
74
describe ( 'Calculate the sum of array of numbers' , ( ) => {
74
- it ( 'should declare a function named sumNumbers' , ( ) => {
75
+ test ( 'should declare a function named sumNumbers' , ( ) => {
75
76
expect ( typeof sumNumbers ) . toBe ( 'function' ) ;
76
77
} ) ;
77
78
78
- it ( 'should return zero if receives an empty array when called' , ( ) => {
79
+ test ( 'should return zero if receives an empty array when called' , ( ) => {
79
80
expect ( sumNumbers ( [ ] ) ) . toBe ( 0 ) ;
80
81
} ) ;
81
82
82
- it ( 'should return the sum with one number array' , ( ) => {
83
+ test ( 'should return the sum with one number array' , ( ) => {
83
84
expect ( sumNumbers ( [ 4 ] ) ) . toBe ( 4 ) ;
84
85
} ) ;
85
86
86
- it ( 'should return zero if all elements are zero' , ( ) => {
87
+ test ( 'should return zero if all elements are zero' , ( ) => {
87
88
expect ( sumNumbers ( [ 0 , 0 , 0 , 0 , 0 ] ) ) . toBe ( 0 ) ;
88
89
} ) ;
89
90
90
- it ( 'should return the sum when passed array of numbers' , ( ) => {
91
+ test ( 'should return the sum when passed array of numbers' , ( ) => {
91
92
expect ( sumNumbers ( [ 10 , 5 , 4 , 32 , 8 ] ) ) . toBe ( 59 ) ;
92
93
} ) ;
93
94
} ) ;
94
95
95
96
describe ( 'Bonus: Calculate the sum' , ( ) => {
96
- it ( 'should declare a function named sum' , ( ) => {
97
+ test ( 'should declare a function named sum' , ( ) => {
97
98
expect ( typeof sum ) . toBe ( 'function' ) ;
98
99
} ) ;
99
100
100
- it ( 'should return zero if receives an empty array when called' , ( ) => {
101
+ test ( 'should return zero if receives an empty array when called' , ( ) => {
101
102
expect ( sum ( [ ] ) ) . toBe ( 0 ) ;
102
103
} ) ;
103
104
104
- it ( 'should return the sum with one number array' , ( ) => {
105
+ test ( 'should return the sum with one number array' , ( ) => {
105
106
expect ( sum ( [ 4 ] ) ) . toBe ( 4 ) ;
106
107
} ) ;
107
108
108
- it ( 'should return zero if all elements are zero' , ( ) => {
109
+ test ( 'should return zero if all elements are zero' , ( ) => {
109
110
expect ( sum ( [ 0 , 0 , 0 , 0 , 0 ] ) ) . toBe ( 0 ) ;
110
111
} ) ;
111
112
112
- it ( 'should return the sum when passed array of numbers' , ( ) => {
113
+ test ( 'should return the sum when passed array of numbers' , ( ) => {
113
114
expect ( sum ( [ 10 , 5 , 4 , 32 , 8 ] ) ) . toBe ( 59 ) ;
114
115
} ) ;
115
116
116
- it ( 'should return the sum when passed array of strings' , ( ) => {
117
+ test ( 'should return the sum when passed array of strings' , ( ) => {
117
118
expect ( sum ( [ 'ana' , 'marco' , 'nicolas' , 'tania' , 'ptwd' ] ) ) . toBe ( 24 ) ;
118
119
} ) ;
119
120
120
- it ( 'should return the sum when passed array of mixed strings and numbers - ' , ( ) => {
121
+ test ( 'should return the sum when passed array of mixed strings and numbers - ' , ( ) => {
121
122
expect ( sum ( [ 6 , 12 , 'miami' , 1 , 'barca' , '200' , 'lisboa' , 8 , 10 ] ) ) . toBe ( 56 ) ;
122
123
} ) ;
123
- it ( 'should return the sum when passed array of mixed strings, numbers and booleans - ' , ( ) => {
124
+ test ( 'should return the sum when passed array of mixed strings, numbers and booleans - ' , ( ) => {
124
125
// false is counted as 0
125
126
expect ( sum ( [ 6 , 12 , 'miami' , 1 , 'barca' , '200' , 'lisboa' , 8 , false ] ) ) . toBe ( 46 ) ;
126
127
// true is counted as 1
127
128
expect ( sum ( [ 6 , 12 , 'miami' , 1 , 'barca' , '200' , 'lisboa' , 8 , true ] ) ) . toBe ( 47 ) ;
128
129
} ) ;
129
- it ( 'should throw an error when unsupported data type (object or array) present in the array' , ( ) => {
130
+ test ( 'should throw an error when unsupported data type (object or array) present in the array' , ( ) => {
130
131
expect ( ( ) => sum ( [ 6 , 12 , 'miami' , 1 , 'barca' , '200' , 'lisboa' , 8 , [ ] , { } ] ) ) . toThrow (
131
132
new Error ( "Unsupported data type sir or ma'am" )
132
133
) ;
133
134
} ) ;
134
135
} ) ;
135
136
136
137
describe ( 'Calculate the average of an array of numbers' , ( ) => {
137
- it ( 'should declare a function named averageNumbers' , ( ) => {
138
+ test ( 'should declare a function named averageNumbers' , ( ) => {
138
139
expect ( typeof averageNumbers ) . toBe ( 'function' ) ;
139
140
} ) ;
140
141
141
- it ( 'should return null if receives an empty array when called' , ( ) => {
142
+ test ( 'should return null if receives an empty array when called' , ( ) => {
142
143
expect ( averageNumbers ( [ ] ) ) . toBe ( null ) ;
143
144
} ) ;
144
145
145
- it ( 'should return the average of a one-element array' , ( ) => {
146
+ test ( 'should return the average of a one-element array' , ( ) => {
146
147
expect ( averageNumbers ( [ 9 ] ) ) . toBe ( 9 ) ;
147
148
} ) ;
148
149
149
- it ( 'should return the average even with negative values' , ( ) => {
150
+ test ( 'should return the average even with negative values' , ( ) => {
150
151
expect ( averageNumbers ( [ 9 , - 3 , - 4 , 6 ] ) ) . toBe ( 2 ) ;
151
152
} ) ;
152
153
153
- it ( 'should return the average of the array' , ( ) => {
154
+ test ( 'should return the average of the array' , ( ) => {
154
155
expect ( averageNumbers ( [ 9 , 10 , 82 , 92 , 32 , 102 , 58 ] ) ) . toBe ( 55 ) ;
155
156
} ) ;
156
157
} ) ;
157
158
158
159
describe ( 'Calculate the average of an array of strings' , ( ) => {
159
- it ( 'should declare a function named averageWordLength' , ( ) => {
160
+ test ( 'should declare a function named averageWordLength' , ( ) => {
160
161
expect ( typeof averageWordLength ) . toBe ( 'function' ) ;
161
162
} ) ;
162
163
163
- it ( 'should return null if receives an empty array when called' , ( ) => {
164
+ test ( 'should return null if receives an empty array when called' , ( ) => {
164
165
expect ( averageWordLength ( [ ] ) ) . toBe ( null ) ;
165
166
} ) ;
166
167
167
- it ( 'should return the average of a one-element array' , ( ) => {
168
+ test ( 'should return the average of a one-element array' , ( ) => {
168
169
expect ( averageWordLength ( [ 'ironhack' ] ) ) . toBe ( 8 ) ;
169
170
} ) ;
170
171
171
- it ( 'should return the average of a the array' , ( ) => {
172
+ test ( 'should return the average of a the array' , ( ) => {
172
173
expect (
173
174
averageWordLength ( [ 'Ironhack' , 'Madrid' , 'Barcelona' , 'Paris' , 'Miami' , 'Mexico' , 'Berlin' , 'Programmers' ] )
174
175
) . toBe ( 7 ) ;
175
176
} ) ;
176
177
} ) ;
177
178
178
179
describe ( 'Bonus: Calculate the average of a mixed elements array' , ( ) => {
179
- it ( 'should declare a function named avg' , ( ) => {
180
+ test ( 'should declare a function named avg' , ( ) => {
180
181
expect ( typeof avg ) . toBe ( 'function' ) ;
181
182
} ) ;
182
183
183
- it ( 'should return null if receives an empty array when called' , ( ) => {
184
+ test ( 'should return null if receives an empty array when called' , ( ) => {
184
185
expect ( avg ( [ ] ) ) . toBe ( null ) ;
185
186
} ) ;
186
187
187
- it ( 'should return the average of the array' , ( ) => {
188
+ test ( 'should return the average of the array' , ( ) => {
188
189
// false is counted as 0
189
190
expect ( avg ( [ 6 , 12 , 'miami' , 1 , 'barca' , '200' , 'lisboa' , 8 , false ] ) ) . toBe ( 5.11 ) ;
190
191
// true is counted as 1
@@ -193,69 +194,69 @@ describe('Bonus: Calculate the average of a mixed elements array', () => {
193
194
} ) ;
194
195
195
196
describe ( 'Unique array' , ( ) => {
196
- it ( 'should declare a function named uniquifyArray' , ( ) => {
197
+ test ( 'should declare a function named uniquifyArray' , ( ) => {
197
198
expect ( typeof uniquifyArray ) . toBe ( 'function' ) ;
198
199
} ) ;
199
200
200
- it ( 'should return null if receives an empty array when called' , ( ) => {
201
+ test ( 'should return null if receives an empty array when called' , ( ) => {
201
202
expect ( uniquifyArray ( [ ] ) ) . toEqual ( null ) ;
202
203
} ) ;
203
204
204
- it ( 'should return the correct uniqified array when an array of the same elements passed as argument' , ( ) => {
205
+ test ( 'should return the correct uniqified array when an array of the same elements passed as argument' , ( ) => {
205
206
expect ( uniquifyArray ( [ 'Ironhack' , 'Ironhack' , 'Ironhack' ] ) ) . toEqual ( [ 'Ironhack' ] ) ;
206
207
} ) ;
207
208
208
- it ( 'should return the same array when no element is repeated' , ( ) => {
209
+ test ( 'should return the same array when no element is repeated' , ( ) => {
209
210
expect ( uniquifyArray ( [ 'Cat' , 'Dog' , 'Cow' ] ) ) . toEqual ( [ 'Cat' , 'Dog' , 'Cow' ] ) ;
210
211
} ) ;
211
212
212
- it ( 'should return the uniquified array' , ( ) => {
213
+ test ( 'should return the uniquified array' , ( ) => {
213
214
expect (
214
215
uniquifyArray ( [ 'iPhone' , 'Samsung' , 'Android' , 'iOS' , 'iPhone' , 'Samsung' , 'Nokia' , 'Blackberry' , 'Android' ] )
215
216
) . toEqual ( [ 'iPhone' , 'Samsung' , 'Android' , 'iOS' , 'Nokia' , 'Blackberry' ] ) ;
216
217
} ) ;
217
218
} ) ;
218
219
219
220
describe ( 'Find elements' , ( ) => {
220
- it ( 'should declare a function named doesWordExist' , ( ) => {
221
+ test ( 'should declare a function named doesWordExist' , ( ) => {
221
222
expect ( typeof doesWordExist ) . toBe ( 'function' ) ;
222
223
} ) ;
223
224
224
- it ( 'should return null if receives an empty array when called' , ( ) => {
225
+ test ( 'should return null if receives an empty array when called' , ( ) => {
225
226
expect ( doesWordExist ( [ ] ) ) . toBe ( null ) ;
226
227
} ) ;
227
228
228
- it ( 'should return true if the word we are looking for is the only one in the array' , ( ) => {
229
+ test ( 'should return true if the word we are looking for is the only one in the array' , ( ) => {
229
230
expect ( doesWordExist ( [ 'machine' ] , 'machine' ) ) . toBe ( true ) ;
230
231
} ) ;
231
232
232
- it ( 'should return false if the word we are looking for is not in the array' , ( ) => {
233
+ test ( 'should return false if the word we are looking for is not in the array' , ( ) => {
233
234
expect ( doesWordExist ( [ 'machine' , 'poison' , 'eat' , 'apple' , 'horse' ] , 'ratatouille' ) ) . toBe ( false ) ;
234
235
} ) ;
235
236
236
- it ( 'should return true if the word we are looking for is in the array' , ( ) => {
237
+ test ( 'should return true if the word we are looking for is in the array' , ( ) => {
237
238
expect ( doesWordExist ( [ 'pizza' , 'sandwich' , 'snack' , 'soda' , 'book' , 'computer' ] , 'book' ) ) . toBe ( true ) ;
238
239
} ) ;
239
240
} ) ;
240
241
241
242
describe ( 'Count repetition' , ( ) => {
242
- it ( 'should declare a function named howManyTimes' , ( ) => {
243
+ test ( 'should declare a function named howManyTimes' , ( ) => {
243
244
expect ( typeof howManyTimes ) . toBe ( 'function' ) ;
244
245
} ) ;
245
246
246
- it ( 'should return 0 (zero) if receives an empty array when called' , ( ) => {
247
+ test ( 'should return 0 (zero) if receives an empty array when called' , ( ) => {
247
248
expect ( howManyTimes ( [ ] ) ) . toBe ( 0 ) ;
248
249
} ) ;
249
250
250
- it ( 'should return 1 (one) when the word appears only one time in the array' , ( ) => {
251
+ test ( 'should return 1 (one) when the word appears only one time in the array' , ( ) => {
251
252
expect ( howManyTimes ( [ 'basketball' , 'football' , 'tennis' ] , 'tennis' ) ) . toBe ( 1 ) ;
252
253
} ) ;
253
254
254
- it ( "should return 0 (zero) when the word doesn't appear in the array" , ( ) => {
255
+ test ( "should return 0 (zero) when the word doesn't appear in the array" , ( ) => {
255
256
expect ( howManyTimes ( [ 'basketball' , 'football' , 'tennis' ] , 'rugby' ) ) . toBe ( 0 ) ;
256
257
} ) ;
257
258
258
- it ( 'should return 5 (five) when the word appears 5 times in the array' , ( ) => {
259
+ test ( 'should return 5 (five) when the word appears 5 times in the array' , ( ) => {
259
260
expect (
260
261
howManyTimes (
261
262
[
@@ -278,11 +279,11 @@ describe('Count repetition', () => {
278
279
} ) ;
279
280
280
281
describe ( 'Bonus Quest - greatestProduct' , ( ) => {
281
- it ( 'should declare a function named greatestProduct' , ( ) => {
282
+ test ( 'should declare a function named greatestProduct' , ( ) => {
282
283
expect ( typeof greatestProduct ) . toBe ( 'function' ) ;
283
284
} ) ;
284
285
285
- it ( 'should return 1 (one) when all numbers of the arrays are 1' , ( ) => {
286
+ test ( 'should return 1 (one) when all numbers of the arrays are 1' , ( ) => {
286
287
let matrix = [
287
288
[ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ] ,
288
289
[ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ] ,
@@ -308,7 +309,7 @@ describe('Bonus Quest - greatestProduct', () => {
308
309
expect ( greatestProduct ( matrix ) ) . toBe ( 1 ) ;
309
310
} ) ;
310
311
311
- it ( 'should return 16 when all the numbers of the arrays are 2' , ( ) => {
312
+ test ( 'should return 16 when all the numbers of the arrays are 2' , ( ) => {
312
313
let matrix = [
313
314
[ 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ] ,
314
315
[ 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ] ,
0 commit comments