Skip to content

Commit b950655

Browse files
solved iteration ironhack-labs#5
1 parent c7a0e42 commit b950655

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/functions-and-arrays.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,11 @@ const wordsUnique = [
238238
'crab',
239239
'crab',
240240
'bee',
241-
'bee'
241+
'foo',
242+
'bee',
243+
'crab',
244+
'crab',
245+
'foo'
242246
];
243247

244248
function uniquifyArray(array) {
@@ -247,17 +251,17 @@ function uniquifyArray(array) {
247251
return null;
248252
}
249253
else {
250-
// loop over words in array
251-
for (let i = 0; i < array.length; i++) {
254+
// loop over words in array (looping backwards)
255+
for (let i = array.length - 1; i >= 0; i--) {
252256
let currentWord = array[i];
253-
let currentWordIndex = i;
254257

255258
// compare current word to all following words in array
256259
for (let j = i+1; j < array.length; j++) {
257260
// remove duplicates
258261
if (currentWord === array[j]) {
259262
array.splice(j,1);
260263
}
264+
else{}
261265
}
262266
}
263267
return array;

0 commit comments

Comments
 (0)