File tree Expand file tree Collapse file tree 1 file changed +8
-15
lines changed Expand file tree Collapse file tree 1 file changed +8
-15
lines changed Original file line number Diff line number Diff line change @@ -121,7 +121,7 @@ function avg(mixedArr) {
121
121
}
122
122
123
123
// Iteration #5: Unique arrays
124
- const wordsUnique = [
124
+ /* const wordsUnique = [
125
125
'crab',
126
126
'poison',
127
127
'contagious',
@@ -133,25 +133,18 @@ const wordsUnique = [
133
133
'communion',
134
134
'simple',
135
135
'bring'
136
- ] ;
136
+ ];*/
137
137
138
- function uniquifyArray ( ) {
138
+ function uniquifyArray ( wordsUnique ) {
139
139
if ( wordsUnique . length === 0 ) {
140
140
return null
141
141
}
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
-
149
142
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 ) ;
153
146
}
154
- console . log ( wordsUnique )
147
+
155
148
return wordsUnique
156
149
}
157
150
@@ -194,7 +187,7 @@ function howManyTimes(wordsCount, word) {
194
187
for ( let i = 0 ; i < wordsCount . length ; ++ i ) {
195
188
if ( wordsCount [ i ] === word ) {
196
189
times += 1 ;
197
- }
190
+ }
198
191
}
199
192
return times
200
193
}
You can’t perform that action at this time.
0 commit comments