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