Skip to content

Commit 822f488

Browse files
committed
FInished iteration ironhack-labs#7
1 parent 1ffbdc1 commit 822f488

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

src/functions-and-arrays.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function averageNumbers(numbersAvg) {
8282
sum += numbersAvg[i];
8383
}
8484
return sum / numbersAvg.length
85-
}
85+
}
8686
}
8787

8888

@@ -99,13 +99,13 @@ function averageWordLength(wordsArr) {
9999
}
100100
return sum / wordsArr.length
101101
}
102-
}
102+
}
103103

104104
// Bonus - Iteration #4.1
105105
function avg(mixedArr) {
106106
if (mixedArr.length === 0) {
107107
return null
108-
}
108+
}
109109
let allAvg = 0
110110
for (let i = 0; i < mixedArr.length; ++i) {
111111
if (typeof mixedArr[i] === 'number') {
@@ -115,7 +115,7 @@ function avg(mixedArr) {
115115
} else if (typeof mixedArr[i] === 'boolean') {
116116
+ mixedArr[i];
117117
allAvg += mixedArr[i]
118-
}
118+
}
119119
}
120120
return allAvg / mixedArr.length
121121
}
@@ -152,27 +152,27 @@ function uniquifyArray() {
152152
}
153153
}
154154
console.log(wordsUnique)
155-
return wordsUnique
156-
}
155+
return wordsUnique
156+
}
157157

158158

159159

160160
// Iteration #6: Find elements
161161
// const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience'];
162162

163-
function doesWordExist(wordsFind, word) {
163+
function doesWordExist(wordsFind, word) {
164164
if (wordsFind.length === 0) {
165165
return null
166166
} else if (wordsFind.includes(word) === true) {
167-
return true
167+
return true
168168
} else if (wordsFind.includes(word) === false) {
169169
return false
170170
}
171171
}
172172

173173

174174
// Iteration #7: Count repetition
175-
const wordsCount = [
175+
/*const wordsCount = [
176176
'machine',
177177
'matter',
178178
'subset',
@@ -184,9 +184,20 @@ const wordsCount = [
184184
'truth',
185185
'disobedience',
186186
'matter'
187-
];
187+
];*/
188188

189-
function howManyTimes() { }
189+
function howManyTimes(wordsCount, word) {
190+
if (wordsCount.length === 0) {
191+
return 0
192+
}
193+
let times = 0
194+
for (let i = 0; i < wordsCount.length; ++i) {
195+
if (wordsCount[i] === word) {
196+
times += 1;
197+
}
198+
}
199+
return times
200+
}
190201

191202

192203

0 commit comments

Comments
 (0)