1
- /* eslint no-undef: 'off' */
2
1
function shuffle ( currentArray ) {
3
- var array = currentArray . map ( function ( arr ) {
2
+ var array = currentArray . map ( function ( arr ) {
4
3
return arr . slice ( ) ;
5
4
} ) ;
6
5
var counter = array . length ;
@@ -13,185 +12,239 @@ function shuffle(currentArray) {
13
12
}
14
13
return array ;
15
14
}
16
- describe ( ' Find the maximum - maxOfTwoNumbers' , function ( ) {
17
- it ( ' Defines maxOfTwoNumbers' , function ( ) {
18
- expect ( typeof maxOfTwoNumbers ) . toBe ( ' function' ) ;
15
+ describe ( " Find the maximum - maxOfTwoNumbers" , function ( ) {
16
+ it ( " Defines maxOfTwoNumbers" , function ( ) {
17
+ expect ( typeof maxOfTwoNumbers ) . toBe ( " function" ) ;
19
18
} ) ;
20
19
21
- it ( ' First parameter larger' , function ( ) {
20
+ it ( " First parameter larger" , function ( ) {
22
21
expect ( maxOfTwoNumbers ( 2 , 1 ) ) . toBe ( 2 ) ;
23
22
} ) ;
24
23
25
- it ( ' Second parameter larger' , function ( ) {
24
+ it ( " Second parameter larger" , function ( ) {
26
25
expect ( maxOfTwoNumbers ( 1 , 3 ) ) . toBe ( 3 ) ;
27
26
} ) ;
28
27
29
- it ( ' First and Second parameter equal' , function ( ) {
28
+ it ( " First and Second parameter equal" , function ( ) {
30
29
expect ( maxOfTwoNumbers ( 4 , 4 ) ) . toBe ( 4 ) ;
31
30
} ) ;
32
31
} ) ;
33
32
34
- describe ( ' Finding Longest Word - findLongestWord' , function ( ) {
35
- it ( ' Defines findLongestWord' , function ( ) {
36
- expect ( typeof findLongestWord ) . toBe ( ' function' ) ;
33
+ describe ( " Finding Longest Word - findLongestWord" , function ( ) {
34
+ it ( " Defines findLongestWord" , function ( ) {
35
+ expect ( typeof findLongestWord ) . toBe ( " function" ) ;
37
36
} ) ;
38
37
39
- it ( ' returns undefined with an empty array' , function ( ) {
40
- expect ( findLongestWord ( [ ] ) ) . toBe ( undefined ) ;
38
+ it ( " returns null with an empty array" , function ( ) {
39
+ expect ( findLongestWord ( [ ] ) ) . toBe ( null ) ;
41
40
} ) ;
42
41
43
- it ( ' returns the word with an 1-word array' , function ( ) {
44
- expect ( findLongestWord ( [ ' foo' ] ) ) . toBe ( ' foo' ) ;
42
+ it ( " returns the word with an 1-word array" , function ( ) {
43
+ expect ( findLongestWord ( [ " foo" ] ) ) . toBe ( " foo" ) ;
45
44
} ) ;
46
45
47
- it ( ' returns the first occurrence word when longest have multiple occurrences ' , function ( ) {
48
- expect ( findLongestWord ( [ ' foo' , ' bar' ] ) ) . toBe ( ' foo' ) ;
49
- expect ( findLongestWord ( [ ' bar' , ' foo' ] ) ) . toBe ( ' bar' ) ;
46
+ it ( " returns the first occurrence word when longest have multiple occurrences " , function ( ) {
47
+ expect ( findLongestWord ( [ " foo" , " bar" ] ) ) . toBe ( " foo" ) ;
48
+ expect ( findLongestWord ( [ " bar" , " foo" ] ) ) . toBe ( " bar" ) ;
50
49
} ) ;
51
50
52
- it ( ' returns the longest occurrence when it has multiple words' , function ( ) {
53
- var words = [ 'a' , ' zab' , ' 12abc' , ' $$abcd' , ' abcde' , ' ironhack' ] ;
51
+ it ( " returns the longest occurrence when it has multiple words" , function ( ) {
52
+ var words = [ "a" , " zab" , " 12abc" , " $$abcd" , " abcde" , " ironhack" ] ;
54
53
for ( var i = 0 ; i < 10 ; i ++ ) {
55
54
words = shuffle ( words ) ;
56
- expect ( findLongestWord ( words ) ) . toBe ( ' ironhack' ) ;
55
+ expect ( findLongestWord ( words ) ) . toBe ( " ironhack" ) ;
57
56
}
58
57
} ) ;
59
58
} ) ;
60
59
61
- describe ( ' Calculating a Sum - sumArray' , function ( ) {
62
- it ( ' Defines sumArray' , function ( ) {
63
- expect ( typeof sumArray ) . toBe ( ' function' ) ;
60
+ describe ( " Calculating a Sum - sumArray" , function ( ) {
61
+ it ( " Defines sumArray" , function ( ) {
62
+ expect ( typeof sumArray ) . toBe ( " function" ) ;
64
63
} ) ;
65
64
66
- it ( ' returns zero with an empty array' , function ( ) {
65
+ it ( " returns zero with an empty array" , function ( ) {
67
66
expect ( sumArray ( [ ] ) ) . toBe ( 0 ) ;
68
67
} ) ;
69
68
70
- it ( ' returns the sum with one number array' , function ( ) {
69
+ it ( " returns the sum with one number array" , function ( ) {
71
70
expect ( sumArray ( [ 4 ] ) ) . toBe ( 4 ) ;
72
71
} ) ;
73
72
74
- it ( ' returns zero if all elements are zero' , function ( ) {
73
+ it ( " returns zero if all elements are zero" , function ( ) {
75
74
expect ( sumArray ( [ 0 , 0 , 0 , 0 , 0 ] ) ) . toBe ( 0 ) ;
76
75
} ) ;
77
76
78
- it ( ' returns the sum' , function ( ) {
77
+ it ( " returns the sum" , function ( ) {
79
78
expect ( sumArray ( [ 10 , 5 , 4 , 32 , 8 ] ) ) . toBe ( 59 ) ;
80
79
} ) ;
81
80
} ) ;
82
81
83
- describe ( ' Calculating the Average - averageNumbers' , function ( ) {
84
- it ( ' Defines averageNumbers' , function ( ) {
85
- expect ( typeof averageNumbers ) . toBe ( ' function' ) ;
82
+ describe ( " Calculating the Average - averageNumbers" , function ( ) {
83
+ it ( " Defines averageNumbers" , function ( ) {
84
+ expect ( typeof averageNumbers ) . toBe ( " function" ) ;
86
85
} ) ;
87
86
88
- it ( ' returns undefined with an empty array' , function ( ) {
89
- expect ( averageNumbers ( [ ] ) ) . toBe ( undefined ) ;
87
+ it ( " returns null with an empty array" , function ( ) {
88
+ expect ( averageNumbers ( [ ] ) ) . toBe ( null ) ;
90
89
} ) ;
91
90
92
- it ( ' returns the average of a unique element array' , function ( ) {
91
+ it ( " returns the average of a unique element array" , function ( ) {
93
92
expect ( averageNumbers ( [ 9 ] ) ) . toBe ( 9 ) ;
94
93
} ) ;
95
94
96
- it ( ' returns the average even with negative values' , function ( ) {
95
+ it ( " returns the average even with negative values" , function ( ) {
97
96
expect ( averageNumbers ( [ 9 , - 3 , - 4 , 6 ] ) ) . toBe ( 2 ) ;
98
97
} ) ;
99
98
100
- it ( ' returns the average of the array' , function ( ) {
99
+ it ( " returns the average of the array" , function ( ) {
101
100
expect ( averageNumbers ( [ 9 , 10 , 82 , 92 , 32 , 102 , 58 ] ) ) . toBe ( 55 ) ;
102
101
} ) ;
103
102
} ) ;
104
103
105
- describe ( ' Calculating the Average - averageWordLength' , function ( ) {
106
- it ( ' Defines averageWordLength' , function ( ) {
107
- expect ( typeof averageWordLength ) . toBe ( ' function' ) ;
104
+ describe ( " Calculating the Average - averageWordLength" , function ( ) {
105
+ it ( " Defines averageWordLength" , function ( ) {
106
+ expect ( typeof averageWordLength ) . toBe ( " function" ) ;
108
107
} ) ;
109
108
110
- it ( ' returns undefined with an empty array' , function ( ) {
111
- expect ( averageWordLength ( [ ] ) ) . toBe ( undefined ) ;
109
+ it ( " returns null with an empty array" , function ( ) {
110
+ expect ( averageWordLength ( [ ] ) ) . toBe ( null ) ;
112
111
} ) ;
113
112
114
- it ( ' returns the average of a unique element array' , function ( ) {
115
- expect ( averageWordLength ( [ ' ironhack' ] ) ) . toBe ( 8 ) ;
113
+ it ( " returns the average of a unique element array" , function ( ) {
114
+ expect ( averageWordLength ( [ " ironhack" ] ) ) . toBe ( 8 ) ;
116
115
} ) ;
117
116
118
- it ( 'returns the average of a the array' , function ( ) {
119
- expect ( averageWordLength ( [ 'Ironhack' , 'Madrid' , 'Barcelona' , 'Paris' , 'Miami' , 'Mexico' , 'Berlin' , 'Programmers' ] ) ) . toBe ( 7 ) ;
117
+ it ( "returns the average of a the array" , function ( ) {
118
+ expect (
119
+ averageWordLength ( [
120
+ "Ironhack" ,
121
+ "Madrid" ,
122
+ "Barcelona" ,
123
+ "Paris" ,
124
+ "Miami" ,
125
+ "Mexico" ,
126
+ "Berlin" ,
127
+ "Programmers"
128
+ ] )
129
+ ) . toBe ( 7 ) ;
120
130
} ) ;
121
131
} ) ;
122
132
123
- describe ( ' Unique Arrays - uniquifyArray' , function ( ) {
124
- it ( ' Defines uniquifyArray' , function ( ) {
125
- expect ( typeof uniquifyArray ) . toBe ( ' function' ) ;
133
+ describe ( " Unique Arrays - uniquifyArray" , function ( ) {
134
+ it ( " Defines uniquifyArray" , function ( ) {
135
+ expect ( typeof uniquifyArray ) . toBe ( " function" ) ;
126
136
} ) ;
127
137
128
- it ( ' returns undefined with an empty array' , function ( ) {
129
- expect ( uniquifyArray ( [ ] ) ) . toBe ( undefined ) ;
138
+ it ( " returns null with an empty array" , function ( ) {
139
+ expect ( uniquifyArray ( [ ] ) ) . toBe ( null ) ;
130
140
} ) ;
131
141
132
- it ( 'returns the correct array when having an array of the same element' , function ( ) {
133
- expect ( uniquifyArray ( [ 'Ironhack' , 'Ironhack' , 'Ironhack' ] ) ) . toEqual ( [ 'Ironhack' ] ) ;
142
+ it ( "returns the correct array when having an array of the same element" , function ( ) {
143
+ expect ( uniquifyArray ( [ "Ironhack" , "Ironhack" , "Ironhack" ] ) ) . toEqual ( [
144
+ "Ironhack"
145
+ ] ) ;
134
146
} ) ;
135
147
136
- it ( ' returns the same array when no element is repeated' , function ( ) {
137
- expect ( uniquifyArray ( [ ' Cat' , ' Dog' , ' Cow' ] ) ) . toEqual ( [ ' Cat' , ' Dog' , ' Cow' ] ) ;
148
+ it ( " returns the same array when no element is repeated" , function ( ) {
149
+ expect ( uniquifyArray ( [ " Cat" , " Dog" , " Cow" ] ) ) . toEqual ( [ " Cat" , " Dog" , " Cow" ] ) ;
138
150
} ) ;
139
151
140
- it ( 'returns the uniquified array' , function ( ) {
141
- expect ( uniquifyArray ( [ 'iPhone' , 'Samsung' , 'Android' , 'iOS' , 'iPhone' , 'Samsung' , 'Nokia' , 'Blackberry' , 'Android' ] ) ) . toEqual ( [ 'iPhone' , 'Samsung' , 'Android' , 'iOS' , 'Nokia' , 'Blackberry' ] ) ;
152
+ it ( "returns the uniquified array" , function ( ) {
153
+ expect (
154
+ uniquifyArray ( [
155
+ "iPhone" ,
156
+ "Samsung" ,
157
+ "Android" ,
158
+ "iOS" ,
159
+ "iPhone" ,
160
+ "Samsung" ,
161
+ "Nokia" ,
162
+ "Blackberry" ,
163
+ "Android"
164
+ ] )
165
+ ) . toEqual ( [ "iPhone" , "Samsung" , "Android" , "iOS" , "Nokia" , "Blackberry" ] ) ;
142
166
} ) ;
143
167
} ) ;
144
168
145
- describe ( ' Finding Elements - doesWordExist' , function ( ) {
146
- it ( ' Defines doesWordExist' , function ( ) {
147
- expect ( typeof doesWordExist ) . toBe ( ' function' ) ;
169
+ describe ( " Finding Elements - doesWordExist" , function ( ) {
170
+ it ( " Defines doesWordExist" , function ( ) {
171
+ expect ( typeof doesWordExist ) . toBe ( " function" ) ;
148
172
} ) ;
149
173
150
- it ( ' returns false with an empty array' , function ( ) {
174
+ it ( " returns false with an empty array" , function ( ) {
151
175
expect ( doesWordExist ( [ ] ) ) . toBe ( false ) ;
152
176
} ) ;
153
177
154
- it ( ' returns true if the word we are looking is the only one on the array' , function ( ) {
155
- expect ( doesWordExist ( [ ' machine' ] , ' machine' ) ) . toBe ( true ) ;
178
+ it ( " returns true if the word we are looking is the only one on the array" , function ( ) {
179
+ expect ( doesWordExist ( [ " machine" ] , " machine" ) ) . toBe ( true ) ;
156
180
} ) ;
157
181
158
- it ( 'returns false if the word we are looking is not in the array' , function ( ) {
159
- expect ( doesWordExist ( [ 'machine' , 'poison' , 'eat' , 'apple' , 'horse' ] , 'ratatouille' ) ) . toBe ( false ) ;
182
+ it ( "returns false if the word we are looking is not in the array" , function ( ) {
183
+ expect (
184
+ doesWordExist (
185
+ [ "machine" , "poison" , "eat" , "apple" , "horse" ] ,
186
+ "ratatouille"
187
+ )
188
+ ) . toBe ( false ) ;
160
189
} ) ;
161
190
162
- it ( 'returns true if the word we are looking is in the array' , function ( ) {
163
- expect ( doesWordExist ( [ 'pizza' , 'sandwich' , 'snack' , 'soda' , 'book' , 'computer' ] , 'book' ) ) . toBe ( true ) ;
191
+ it ( "returns true if the word we are looking is in the array" , function ( ) {
192
+ expect (
193
+ doesWordExist (
194
+ [ "pizza" , "sandwich" , "snack" , "soda" , "book" , "computer" ] ,
195
+ "book"
196
+ )
197
+ ) . toBe ( true ) ;
164
198
} ) ;
165
199
} ) ;
166
200
167
- describe ( ' Counting Repetition - howManyTimes' , function ( ) {
168
- it ( ' Defines howManyTimes' , function ( ) {
169
- expect ( typeof howManyTimes ) . toBe ( ' function' ) ;
201
+ describe ( " Counting Repetition - howManyTimes" , function ( ) {
202
+ it ( " Defines howManyTimes" , function ( ) {
203
+ expect ( typeof howManyTimes ) . toBe ( " function" ) ;
170
204
} ) ;
171
205
172
- it ( ' returns false with an empty array' , function ( ) {
206
+ it ( " returns false with an empty array" , function ( ) {
173
207
expect ( howManyTimes ( [ ] ) ) . toBe ( false ) ;
174
208
} ) ;
175
209
176
- it ( 'returns one when the word appears only one time on the array' , function ( ) {
177
- expect ( howManyTimes ( [ 'basketball' , 'football' , 'tennis' ] , 'tennis' ) ) . toBe ( 1 ) ;
178
- } ) ;
179
-
180
- it ( 'returns zero when the word does not appears on the array' , function ( ) {
181
- expect ( howManyTimes ( [ 'basketball' , 'football' , 'tennis' ] , 'rugby' ) ) . toBe ( 0 ) ;
182
- } ) ;
183
-
184
- it ( 'returns five when the word appears 5 times on the array' , function ( ) {
185
- expect ( howManyTimes ( [ 'basketball' , 'football' , 'tennis' , 'rugby' , 'rugby' , 'ping pong' , 'rugby' , 'basketball' , 'rugby' , 'handball' , 'rugby' ] , 'rugby' ) ) . toBe ( 5 ) ;
210
+ it ( "returns one when the word appears only one time on the array" , function ( ) {
211
+ expect ( howManyTimes ( [ "basketball" , "football" , "tennis" ] , "tennis" ) ) . toBe (
212
+ 1
213
+ ) ;
214
+ } ) ;
215
+
216
+ it ( "returns zero when the word does not appears on the array" , function ( ) {
217
+ expect ( howManyTimes ( [ "basketball" , "football" , "tennis" ] , "rugby" ) ) . toBe ( 0 ) ;
218
+ } ) ;
219
+
220
+ it ( "returns five when the word appears 5 times on the array" , function ( ) {
221
+ expect (
222
+ howManyTimes (
223
+ [
224
+ "basketball" ,
225
+ "football" ,
226
+ "tennis" ,
227
+ "rugby" ,
228
+ "rugby" ,
229
+ "ping pong" ,
230
+ "rugby" ,
231
+ "basketball" ,
232
+ "rugby" ,
233
+ "handball" ,
234
+ "rugby"
235
+ ] ,
236
+ "rugby"
237
+ )
238
+ ) . toBe ( 5 ) ;
186
239
} ) ;
187
240
} ) ;
188
241
189
- describe ( ' Bonus Quest - greatestProduct' , function ( ) {
190
- it ( ' Defines greatestProduct' , function ( ) {
191
- expect ( typeof greatestProduct ) . toBe ( ' function' ) ;
242
+ describe ( " Bonus Quest - greatestProduct" , function ( ) {
243
+ it ( " Defines greatestProduct" , function ( ) {
244
+ expect ( typeof greatestProduct ) . toBe ( " function" ) ;
192
245
} ) ;
193
246
194
- it ( ' Return 1 when all the numbers of the arrays are 1' , function ( ) {
247
+ it ( " Return 1 when all the numbers of the arrays are 1" , function ( ) {
195
248
var matrix = [
196
249
[ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ] ,
197
250
[ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ] ,
@@ -217,7 +270,7 @@ describe('Bonus Quest - greatestProduct', function () {
217
270
expect ( greatestProduct ( matrix ) ) . toBe ( 1 ) ;
218
271
} ) ;
219
272
220
- it ( ' Return 16 when all the numbers of the arrays are 2' , function ( ) {
273
+ it ( " Return 16 when all the numbers of the arrays are 2" , function ( ) {
221
274
var matrix = [
222
275
[ 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ] ,
223
276
[ 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ] ,
@@ -243,4 +296,3 @@ describe('Bonus Quest - greatestProduct', function () {
243
296
expect ( greatestProduct ( matrix ) ) . toBe ( 16 ) ;
244
297
} ) ;
245
298
} ) ;
246
-
0 commit comments