@@ -63,14 +63,26 @@ const wordsArr = [
63
63
'correspond' ,
64
64
'linen' ,
65
65
'motif' ,
66
- 'hole' ,
66
+ 'hole' ,
67
67
'smell' ,
68
68
'smart' ,
69
69
'chaos' ,
70
70
'fuel' ,
71
71
'palace'
72
72
] ;
73
73
74
+ function averageWordLength ( arr ) {
75
+ let sumArr = 0 ;
76
+ if ( arr . length === 0 ) {
77
+ return null ;
78
+ }
79
+ for ( let i = 0 ; i < arr . length ; i ++ ) {
80
+ sumArr += arr [ i ] . length ;
81
+ }
82
+ let arrayAvg = sumArr / arr . length ;
83
+ return arrayAvg ;
84
+ } ;
85
+
74
86
// Iteration #5: Unique arrays
75
87
const wordsUnique = [
76
88
'crab' ,
@@ -86,6 +98,23 @@ const wordsUnique = [
86
98
'bring'
87
99
] ;
88
100
101
+ function uniquifyArray ( arr ) {
102
+ if ( arr . length === 0 ) {
103
+ return [ ] ;
104
+ }
105
+ let uniqueArray = [ ] ;
106
+ for ( let i = 0 ; i < arr . length ; i ++ ) {
107
+ if ( uniqueArray . includes ( arr [ i ] ) == false ) {
108
+ uniqueArray . push ( arr [ i ] ) ;
109
+ } else if ( uniqueArray . includes ( arr [ i ] ) == true ) {
110
+ continue ;
111
+ }
112
+ }
113
+ return uniqueArray ;
114
+ }
115
+
116
+ uniquifyArray ( wordsUnique ) ;
117
+
89
118
// Iteration #6: Find elements
90
119
const wordsFind = [
91
120
'machine' ,
@@ -98,6 +127,18 @@ const wordsFind = [
98
127
'disobedience'
99
128
] ;
100
129
130
+ function doesWordExist ( arr , word ) {
131
+ if ( arr . length === 0 ) {
132
+ return false ;
133
+ }
134
+ for ( let elem of arr ) {
135
+ if ( elem === word ) {
136
+ return true ;
137
+ }
138
+ }
139
+ return false ;
140
+ }
141
+
101
142
// Iteration #7: Count repetition
102
143
const wordsCount = [
103
144
'machine' ,
@@ -113,6 +154,16 @@ const wordsCount = [
113
154
'matter'
114
155
] ;
115
156
157
+ function howManyTimes ( arr , word ) {
158
+ let count = 0 ;
159
+ for ( let el of arr ) {
160
+ if ( el === word ) {
161
+ count ++
162
+ }
163
+ }
164
+ return count ;
165
+ }
166
+
116
167
// Iteration #8: Bonus
117
168
118
169
const matrix = [
0 commit comments