Skip to content

Commit 5c8e6ec

Browse files
committed
"Finished" iteration ironhack-labs#5
1 parent 822f488 commit 5c8e6ec

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

src/functions-and-arrays.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function avg(mixedArr) {
121121
}
122122

123123
// Iteration #5: Unique arrays
124-
const wordsUnique = [
124+
/*const wordsUnique = [
125125
'crab',
126126
'poison',
127127
'contagious',
@@ -133,25 +133,18 @@ const wordsUnique = [
133133
'communion',
134134
'simple',
135135
'bring'
136-
];
136+
];*/
137137

138-
function uniquifyArray() {
138+
function uniquifyArray(wordsUnique) {
139139
if (wordsUnique.length === 0) {
140140
return null
141141
}
142-
143-
wordsUnique.sort(function (a, b) {
144-
if (a === b) return -1
145-
if (a < b) return 0
146-
if (a > b) return 1
147-
})
148-
149142
for (let i = 0; i < wordsUnique.length; ++i) {
150-
if (wordsUnique[i].localeCompare(wordsUnique[i + 1]) === 0) {
151-
wordsUnique.splice(i + 1, 1);
152-
}
143+
for (let j = i + 1; j < wordsUnique.length; ++j)
144+
if (wordsUnique[i] === wordsUnique[j])
145+
wordsUnique.splice(j, 1);
153146
}
154-
console.log(wordsUnique)
147+
155148
return wordsUnique
156149
}
157150

@@ -194,7 +187,7 @@ function howManyTimes(wordsCount, word) {
194187
for (let i = 0; i < wordsCount.length; ++i) {
195188
if (wordsCount[i] === word) {
196189
times += 1;
197-
}
190+
}
198191
}
199192
return times
200193
}

0 commit comments

Comments
 (0)