@@ -44,7 +44,27 @@ function sumNumbers(someArray) {
44
44
45
45
46
46
// Iteration #3.1 Bonus:
47
- function sum ( ) { }
47
+ // calculates the sum for array filled with (almost) any type of data
48
+ function sum ( someArray ) {
49
+ let sum = 0 ;
50
+ //1. booleans: add 1 or 0 -> true + true = 2, so we good
51
+ //2. string: add length
52
+ //3. integers: add value
53
+ if ( someArray . length === 0 ) {
54
+ return null ;
55
+ } else {
56
+ for ( let i = 0 ; i < someArray . length ; i ++ ) {
57
+ if ( typeof someArray [ i ] === "string" || typeof someArray [ i ] === "boolean" ) {
58
+ sum += someArray [ i ] . length ;
59
+ } else if ( typeof someArray [ i ] === "number" ) {
60
+ sum += someArray [ i ] ;
61
+ }
62
+ }
63
+ }
64
+ return sum ;
65
+ }
66
+
67
+
48
68
49
69
50
70
@@ -82,7 +102,11 @@ function averageWordLength(wordsArr) {
82
102
}
83
103
84
104
// Bonus - Iteration #4.1
85
- function avg ( ) { }
105
+ //calc avg of array filled w numbers, strings, booleans
106
+ function avg ( someArray ) {
107
+ let avg = sum ( someArray ) / someArray . length ;
108
+ return avg ;
109
+ }
86
110
87
111
// Iteration #5: Unique arrays
88
112
const wordsUnique = [
@@ -185,7 +209,30 @@ const matrix = [
185
209
[ 1 , 70 , 54 , 71 , 83 , 51 , 54 , 69 , 16 , 92 , 33 , 48 , 61 , 43 , 52 , 1 , 89 , 19 , 67 , 48 ]
186
210
] ;
187
211
188
- function greatestProduct ( ) { }
212
+
213
+ //find the greates product of 4 adjacent number
214
+
215
+ function greatestProduct ( someMatrix ) {
216
+ //create empty variable to store values
217
+ //get the product of n1 n2 n3 n4, store it.
218
+ //get the product of n2 n3 n4 n5, compare it with what's in the variable.
219
+ //if second product is larger, replace it.
220
+ //so on, for rows
221
+ let greatestProduct = "" ;
222
+ let productOfFour = "" ;
223
+ let n1 = someMatrix . length [ i ] [ j ] ;
224
+ let n2 = someMatrix . length [ i ] [ j + 1 ] ;
225
+ let n3 = someMatrix . length [ i ] [ j + 2 ] ;
226
+ let n4 = someMatrix . length [ i ] [ j + 3 ] ;
227
+ for ( i = 0 ; i > someMatrix . length ; i ++ ) {
228
+ for ( j = 0 ; j > someMatrix . length [ j ] ; j ++ ) {
229
+ productOfFour = j *
230
+ }
231
+ }
232
+
233
+ }
234
+
235
+ //
189
236
190
237
191
238
0 commit comments