Skip to content

Commit f3654aa

Browse files
committed
add: until ironhack-labs#6
1 parent aea7b88 commit f3654aa

File tree

1 file changed

+43
-7
lines changed

1 file changed

+43
-7
lines changed

src/functions-and-arrays.js

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,24 +137,60 @@ const wordsUnique = [
137137
];
138138

139139
function uniquifyArray(arr) {
140-
let i = 0;
140+
141+
let i=0;
141142
while (i<arr.length) {
142-
if (arr.includes(arr[i],i+1)) {
143-
144-
arr.splice(arr.indexOf(arr[i]),1);
145-
146-
}
143+
let indices = [];
144+
let element = arr[i];
145+
let idx = arr.indexOf(element);
146+
// console.log(element);
147+
//console.log(idx);
148+
while (idx != -1) {
149+
indices.push(idx);
150+
//console.log(indices);
151+
idx = arr.indexOf(element, idx +1);
152+
//console.log(idx);
153+
}
154+
let j=1;
155+
while (j < indices.length) {
156+
//console.log(indices);
157+
arr.splice(indices[j],1);
158+
// console.log(arr);
159+
if (indices[j+1]) {
160+
indices[j+1] = indices[j+1] - 1;
161+
}
162+
j++;
163+
}
147164
i++;
148165
}
166+
//console.log(arr);
149167
return arr;
150168
}
169+
151170

152171

153172

154173
// Iteration #6: Find elements
155174
const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience'];
156175

157-
function doesWordExist() {}
176+
function doesWordExist(arr, word) {
177+
let i=0;
178+
let exists = false;
179+
while (i<arr.length) {
180+
console.log(arr[i]);
181+
console.log(exists);
182+
if (arr[i] === word) {
183+
exists = true;
184+
break;
185+
}
186+
i++;
187+
}
188+
if (exists === false) {
189+
return false;
190+
} else {
191+
return true;
192+
}
193+
}
158194

159195

160196

0 commit comments

Comments
 (0)