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