11function shuffle ( currentArray ) {
22 const array = currentArray . map ( arr => arr . slice ( ) ) ;
3- const counter = array . length ;
3+ let counter = array . length ;
44
55 while ( counter > 0 ) {
66 let index = Math . floor ( Math . random ( ) * counter ) ;
@@ -11,239 +11,240 @@ function shuffle(currentArray) {
1111 }
1212 return array ;
1313}
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' ) ;
1718 } ) ;
1819
19- it ( " First parameter larger" , ( ) => {
20+ it ( ' First parameter larger' , ( ) => {
2021 expect ( maxOfTwoNumbers ( 2 , 1 ) ) . toBe ( 2 ) ;
2122 } ) ;
2223
23- it ( " Second parameter larger" , ( ) => {
24+ it ( ' Second parameter larger' , ( ) => {
2425 expect ( maxOfTwoNumbers ( 1 , 3 ) ) . toBe ( 3 ) ;
2526 } ) ;
2627
27- it ( " First and Second parameter equal" , ( ) => {
28+ it ( ' First and Second parameter equal' , ( ) => {
2829 expect ( maxOfTwoNumbers ( 4 , 4 ) ) . toBe ( 4 ) ;
2930 } ) ;
3031} ) ;
3132
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' ) ;
3536 } ) ;
3637
37- it ( " returns null when called with an empty array" , ( ) => {
38+ it ( ' returns null when called with an empty array' , ( ) => {
3839 expect ( findLongestWord ( [ ] ) ) . toBe ( null ) ;
3940 } ) ;
4041
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' ) ;
4344 } ) ;
4445
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' ) ;
4849 } ) ;
4950
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' ] ;
5253 for ( let i = 0 ; i < 10 ; i ++ ) {
5354 words = shuffle ( words ) ;
54- expect ( findLongestWord ( words ) ) . toBe ( " ironhack" ) ;
55+ expect ( findLongestWord ( words ) ) . toBe ( ' ironhack' ) ;
5556 }
5657 } ) ;
5758} ) ;
5859
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' ) ;
6263 } ) ;
6364
64- it ( " returns zero with an empty array" , ( ) => {
65+ it ( ' returns zero with an empty array' , ( ) => {
6566 expect ( sumArray ( [ ] ) ) . toBe ( 0 ) ;
6667 } ) ;
6768
68- it ( " returns the sum with one number array" , ( ) => {
69+ it ( ' returns the sum with one number array' , ( ) => {
6970 expect ( sumArray ( [ 4 ] ) ) . toBe ( 4 ) ;
7071 } ) ;
7172
72- it ( " returns zero if all elements are zero" , ( ) => {
73+ it ( ' returns zero if all elements are zero' , ( ) => {
7374 expect ( sumArray ( [ 0 , 0 , 0 , 0 , 0 ] ) ) . toBe ( 0 ) ;
7475 } ) ;
7576
76- it ( " returns the sum" , ( ) => {
77+ it ( ' returns the sum' , ( ) => {
7778 expect ( sumArray ( [ 10 , 5 , 4 , 32 , 8 ] ) ) . toBe ( 59 ) ;
7879 } ) ;
7980} ) ;
8081
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' ) ;
8485 } ) ;
8586
86- it ( " returns null with an empty array" , ( ) => {
87+ it ( ' returns null with an empty array' , ( ) => {
8788 expect ( averageNumbers ( [ ] ) ) . toBe ( null ) ;
8889 } ) ;
8990
90- it ( " returns the average of a unique element array" , ( ) => {
91+ it ( ' returns the average of a unique element array' , ( ) => {
9192 expect ( averageNumbers ( [ 9 ] ) ) . toBe ( 9 ) ;
9293 } ) ;
9394
94- it ( " returns the average even with negative values" , ( ) => {
95+ it ( ' returns the average even with negative values' , ( ) => {
9596 expect ( averageNumbers ( [ 9 , - 3 , - 4 , 6 ] ) ) . toBe ( 2 ) ;
9697 } ) ;
9798
98- it ( " returns the average of the array" , ( ) => {
99+ it ( ' returns the average of the array' , ( ) => {
99100 expect ( averageNumbers ( [ 9 , 10 , 82 , 92 , 32 , 102 , 58 ] ) ) . toBe ( 55 ) ;
100101 } ) ;
101102} ) ;
102103
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' ) ;
106107 } ) ;
107108
108- it ( " returns null with an empty array" , ( ) => {
109+ it ( ' returns null with an empty array' , ( ) => {
109110 expect ( averageWordLength ( [ ] ) ) . toBe ( null ) ;
110111 } ) ;
111112
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 ) ;
114115 } ) ;
115116
116- it ( " returns the average of a the array" , ( ) => {
117+ it ( ' returns the average of a the array' , ( ) => {
117118 expect (
118119 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'
127128 ] )
128129 ) . toBe ( 7 ) ;
129130 } ) ;
130131} ) ;
131132
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' ) ;
135136 } ) ;
136137
137- it ( " returns [] with an empty array" , ( ) => {
138+ it ( ' returns [] with an empty array' , ( ) => {
138139 expect ( uniquifyArray ( [ ] ) ) . toEqual ( [ ] ) ;
139140 } ) ;
140141
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'
144145 ] ) ;
145146 } ) ;
146147
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' ] ) ;
149150 } ) ;
150151
151- it ( " returns the uniquified array" , ( ) => {
152+ it ( ' returns the uniquified array' , ( ) => {
152153 expect (
153154 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'
163164 ] )
164- ) . toEqual ( [ " iPhone" , " Samsung" , " Android" , " iOS" , " Nokia" , " Blackberry" ] ) ;
165+ ) . toEqual ( [ ' iPhone' , ' Samsung' , ' Android' , ' iOS' , ' Nokia' , ' Blackberry' ] ) ;
165166 } ) ;
166167} ) ;
167168
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' ) ;
171172 } ) ;
172173
173- it ( " returns false with an empty array" , ( ) => {
174+ it ( ' returns false with an empty array' , ( ) => {
174175 expect ( doesWordExist ( [ ] ) ) . toBe ( false ) ;
175176 } ) ;
176177
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 ) ;
179180 } ) ;
180181
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' , ( ) => {
182183 expect (
183184 doesWordExist (
184- [ " machine" , " poison" , " eat" , " apple" , " horse" ] ,
185- " ratatouille"
185+ [ ' machine' , ' poison' , ' eat' , ' apple' , ' horse' ] ,
186+ ' ratatouille'
186187 )
187188 ) . toBe ( false ) ;
188189 } ) ;
189190
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' , ( ) => {
191192 expect (
192193 doesWordExist (
193- [ " pizza" , " sandwich" , " snack" , " soda" , " book" , " computer" ] ,
194- " book"
194+ [ ' pizza' , ' sandwich' , ' snack' , ' soda' , ' book' , ' computer' ] ,
195+ ' book'
195196 )
196197 ) . toBe ( true ) ;
197198 } ) ;
198199} ) ;
199200
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' ) ;
203204 } ) ;
204205
205- it ( " returns 0 with an empty array" , ( ) => {
206+ it ( ' returns 0 with an empty array' , ( ) => {
206207 expect ( howManyTimes ( [ ] ) ) . toBe ( 0 ) ;
207208 } ) ;
208209
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 (
211212 1
212213 ) ;
213214 } ) ;
214215
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 ) ;
217218 } ) ;
218219
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' , ( ) => {
220221 expect (
221222 howManyTimes (
222223 [
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'
234235 ] ,
235- " rugby"
236+ ' rugby'
236237 )
237238 ) . toBe ( 5 ) ;
238239 } ) ;
239240} ) ;
240241
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' ) ;
244245 } ) ;
245246
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' , ( ) => {
247248 let matrix = [
248249 [ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ] ,
249250 [ 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", () => {
269270 expect ( greatestProduct ( matrix ) ) . toBe ( 1 ) ;
270271 } ) ;
271272
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' , ( ) => {
273274 let matrix = [
274275 [ 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ] ,
275276 [ 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ] ,
0 commit comments