Skip to content

Commit b471925

Browse files
committed
Iteration ironhack-labs#5: Unique arrays & Iteration ironhack-labs#6: Find elements - DONE
1 parent 9c706a4 commit b471925

File tree

1 file changed

+37
-18
lines changed

1 file changed

+37
-18
lines changed

src/functions-and-arrays.js

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -139,31 +139,50 @@ const wordsUnique = [
139139
'bring'
140140
];
141141

142+
function uniquifyArray(wordsUnique){
143+
let theWordsUnique = [...new Set(wordsUnique)]
144+
if (wordsUnique.length === 0|| typeof wordsUnique !== "object") {
145+
return null
146+
} else {
147+
return theWordsUnique
148+
}
149+
}
142150

143-
function uniquifyArray(wordsUnique) {
144-
wordsUnique.sort()
145-
let newWordsUnique = [];
146-
if (wordsUnique.length === 0|| typeof wordsUnique !== "object") {
147-
return null
148-
} else {
149-
for(let i=0; i < wordsUnique.length; i++){
150-
let newWordsUnique = ['hola']
151-
if (wordsUnique[i] === wordsUnique[i + 1]) {
152-
wordsUnique.splice(i,1)
153-
}
154-
}
155-
return wordsUnique
156-
}
157-
}
151+
// function uniquifyArray(wordsUnique) {
152+
// wordsUnique.sort()
153+
// let newWordsUnique = [];
154+
// if (wordsUnique.length === 0|| typeof wordsUnique !== "object") {
155+
// return null
156+
// } else {
157+
// for(let i=0; i < wordsUnique.length; i++){
158+
// let newWordsUnique = ['hola']
159+
// if (wordsUnique[i] === wordsUnique[i + 1]) {
160+
// wordsUnique.splice(i,1)
161+
// }
162+
// }
163+
// return wordsUnique
164+
// }
165+
// }
158166

159167

160168

161169
// Iteration #6: Find elements
162170
const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience'];
171+
let theWord = 'subset';
163172

164-
function doesWordExist() {}
165-
166-
173+
function doesWordExist(wordsFind, theWord) {
174+
let theAnswer = false
175+
if (theWord === '' || wordsFind.length === 0) {
176+
return null
177+
} else {
178+
for (let i=0; i < wordsFind.length; i++) {
179+
if (theWord === wordsFind[i]) {
180+
theAnswer = true
181+
}
182+
}
183+
return theAnswer
184+
}
185+
}
167186

168187
// Iteration #7: Count repetition
169188
const wordsCount = [

0 commit comments

Comments
 (0)