@@ -138,6 +138,19 @@ function uniquifyArray(wordsArr) {
138
138
// Iteration #6: Find elements
139
139
const wordsFind = [ 'machine' , 'subset' , 'trouble' , 'starting' , 'matter' , 'eating' , 'truth' , 'disobedience' ] ;
140
140
141
+ function doesWordExist ( wordsArr , wordToSearch ) {
142
+ if ( wordsArr . length <= 0 ) {
143
+ return null
144
+ }
145
+
146
+ for ( let i = 0 ; i < wordsArr . length ; i ++ ) {
147
+ if ( wordsArr [ i ] === wordToSearch ) {
148
+ return true
149
+ }
150
+ }
151
+ return false
152
+ }
153
+
141
154
// Iteration #7: Count repetition
142
155
const wordsCount = [
143
156
'machine' ,
@@ -153,6 +166,17 @@ const wordsCount = [
153
166
'matter'
154
167
] ;
155
168
169
+ function howManyTimes ( wordsArr , wordToCount ) {
170
+ let counter = 0
171
+ for ( let i = 0 ; i < wordsArr . length ; i ++ ) {
172
+ if ( wordsArr [ i ] === wordToCount ) {
173
+ counter ++
174
+ }
175
+ }
176
+
177
+ return counter
178
+ }
179
+
156
180
// Iteration #8: Bonus
157
181
158
182
const matrix = [
@@ -177,3 +201,34 @@ const matrix = [
177
201
[ 20 , 73 , 35 , 29 , 78 , 31 , 90 , 1 , 74 , 31 , 49 , 71 , 48 , 86 , 81 , 16 , 23 , 57 , 5 , 54 ] ,
178
202
[ 1 , 70 , 54 , 71 , 83 , 51 , 54 , 69 , 16 , 92 , 33 , 48 , 61 , 43 , 52 , 1 , 89 , 19 , 67 , 48 ]
179
203
] ;
204
+
205
+ function greatestProduct ( matrix ) {
206
+ //let currentGreatestProductArr = []
207
+ let currentHighestProduct = 0
208
+ for ( let i = 0 ; i < matrix . length ; i ++ ) {
209
+ for ( let j = 0 ; j < matrix [ i ] . length ; j ++ ) {
210
+ let tempProductHorz = 0
211
+ let tempProductVert = 0
212
+ if ( j + 3 < matrix [ i ] . length ) {
213
+ tempProductHorz = matrix [ i ] [ j ] * matrix [ i ] [ j + 1 ] * matrix [ i ] [ j + 2 ] * matrix [ i ] [ j + 3 ]
214
+ }
215
+ if ( i + 3 < matrix . length ) {
216
+ tempProductVert = matrix [ i ] [ j ] * matrix [ i + 1 ] [ j ] * matrix [ i + 2 ] [ j ] * matrix [ i + 3 ] [ j ]
217
+ }
218
+ if ( tempProductHorz > tempProductVert ) {
219
+ if ( currentHighestProduct < tempProductHorz ) {
220
+ currentHighestProduct = tempProductHorz
221
+ //currentGreatestProductArr = [matrix[i][j], matrix[i][j + 1] , matrix[i][j + 2] , matrix[i][j + 3]]
222
+ }
223
+ }
224
+ else {
225
+ if ( currentHighestProduct < tempProductVert ) {
226
+ currentHighestProduct = tempProductVert
227
+ //currentGreatestProductArr = [ matrix[i][j] , matrix[i + 1][j] , matrix[i+ 2][j] , matrix[i+ 3][j]]
228
+ }
229
+ }
230
+ }
231
+ }
232
+ console . log ( currentHighestProduct )
233
+ return currentHighestProduct
234
+ }
0 commit comments