Skip to content

Commit c7a0e42

Browse files
tried to solve iteration ironhack-labs#5
1 parent 1dc1682 commit c7a0e42

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/functions-and-arrays.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -233,25 +233,34 @@ avg(mixedArr);
233233
// ----------------------------------------
234234

235235
const wordsUnique = [
236+
'foo',
236237
'crab',
237-
'poison',
238-
'contagious',
239-
'simple',
240-
'bring',
241-
'sharp',
242-
'playground',
243-
'poison',
244-
'communion',
245-
'simple',
246-
'bring'
238+
'crab',
239+
'crab',
240+
'bee',
241+
'bee'
247242
];
248243

249244
function uniquifyArray(array) {
245+
// return null if receives an empty array when called
250246
if (array == "") {
251247
return null;
252248
}
253249
else {
254-
250+
// loop over words in array
251+
for (let i = 0; i < array.length; i++) {
252+
let currentWord = array[i];
253+
let currentWordIndex = i;
254+
255+
// compare current word to all following words in array
256+
for (let j = i+1; j < array.length; j++) {
257+
// remove duplicates
258+
if (currentWord === array[j]) {
259+
array.splice(j,1);
260+
}
261+
}
262+
}
263+
return array;
255264
}
256265
}
257266

0 commit comments

Comments
 (0)