File tree 1 file changed +20
-11
lines changed
1 file changed +20
-11
lines changed Original file line number Diff line number Diff line change @@ -233,25 +233,34 @@ avg(mixedArr);
233
233
// ----------------------------------------
234
234
235
235
const wordsUnique = [
236
+ 'foo' ,
236
237
'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'
247
242
] ;
248
243
249
244
function uniquifyArray ( array ) {
245
+ // return null if receives an empty array when called
250
246
if ( array == "" ) {
251
247
return null ;
252
248
}
253
249
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 ;
255
264
}
256
265
}
257
266
You can’t perform that action at this time.
0 commit comments