File tree Expand file tree Collapse file tree 4 files changed +31
-9
lines changed Expand file tree Collapse file tree 4 files changed +31
-9
lines changed Original file line number Diff line number Diff line change 1
- ' use strict' ;
1
+ " use strict" ;
2
2
3
3
const removeElement = ( array , item ) => {
4
- // Remove item from array modifying original array
4
+ return array . filter ( function ( x ) {
5
+ return x != item ;
6
+ } ) ;
5
7
} ;
6
8
7
9
module . exports = { removeElement } ;
Original file line number Diff line number Diff line change 1
- ' use strict' ;
1
+ " use strict" ;
2
2
3
3
const removeElements = ( array , ...items ) => {
4
- // Remove multiple items from array modifying original array
4
+ for ( const val of items ) {
5
+ const index = array . indexOf ( val ) ;
6
+ if ( index !== - 1 ) array . splice ( index , 1 ) ;
7
+ }
8
+ return array ;
5
9
} ;
6
10
7
11
module . exports = { removeElements } ;
Original file line number Diff line number Diff line change 1
- ' use strict' ;
1
+ " use strict" ;
2
2
3
3
// Create and return a new array without duplicate elements
4
4
// Don't modify initial array
5
5
6
- const unique = ( array ) => [ ] ;
6
+ const unique = ( array ) => {
7
+ //let unique = [...new Set(array)];
8
+ const newArray = [ ] ;
9
+ for ( const item of array ) {
10
+ if ( ! newArray . includes ( item ) ) {
11
+ newArray . push ( item ) ;
12
+ }
13
+ }
14
+ return newArray ;
15
+ } ;
7
16
8
17
module . exports = { unique } ;
Original file line number Diff line number Diff line change 1
- ' use strict' ;
1
+ " use strict" ;
2
2
3
3
// Find difference of two arrays
4
4
// elements from array1 that are not includes in array2
5
5
6
- const difference = ( array1 , array2 ) => [ ] ;
7
-
6
+ const difference = ( array1 , array2 ) => {
7
+ const dif = [ ] ;
8
+ for ( const item of array1 ) {
9
+ if ( ! array2 . includes ( item ) ) {
10
+ dif . push ( item ) ;
11
+ }
12
+ }
13
+ return dif ;
14
+ } ;
8
15
module . exports = { difference } ;
You can’t perform that action at this time.
0 commit comments