Skip to content

Commit 807d81d

Browse files
committed
Iteration ironhack-labs#7 Done
1 parent 4cffbaa commit 807d81d

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/functions-and-arrays.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,19 @@ console.log(uniquifyArray(wordsUnique));
114114
// Iteration #6: Find elements
115115
const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience'];
116116

117-
function doesWordExist() {}
118-
117+
function doesWordExist(theArray, theGuess) {
118+
if (theArray.length === 0) {
119+
return null;
120+
} else {
121+
if (theArray.includes(theGuess)) {
122+
return true;
123+
} else {
124+
return false;
125+
}
126+
}
127+
}
119128

129+
console.log(doesWordExist(wordsFind, "machine"));
120130

121131
// Iteration #7: Count repetition
122132
const wordsCount = [
@@ -133,9 +143,17 @@ const wordsCount = [
133143
'matter'
134144
];
135145

136-
function howManyTimes() {}
137-
146+
function howManyTimes(anArray, aWord) {
147+
let countWord = 0;
148+
for (let i = 0; i < anArray.length; i += 1) {
149+
if (aWord === anArray[i]) {
150+
countWord += 1;
151+
}
152+
}
153+
return countWord;
154+
}
138155

156+
console.log(howManyTimes(wordsCount, "matter"));
139157

140158
// Iteration #8: Bonus
141159
const matrix = [

0 commit comments

Comments
 (0)