File tree 1 file changed +35
-0
lines changed
Roadmap/18 - CONJUNTOS/typescript
1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ let set : number [ ] = [ ] ;
2
+ set . push ( 10 ) ;
3
+ set . unshift ( 1 ) ;
4
+ set . push ( 11 , 12 ) ;
5
+ set . splice ( 1 , 0 , 2 , 3 ) ;
6
+ set . splice ( 2 , 1 ) ;
7
+ set [ 2 ] = 5 ;
8
+ let elementExist : boolean = set . includes ( 3 ) ;
9
+ console . log ( elementExist ) ;
10
+ console . log ( set ) ;
11
+ set = [ ] ;
12
+ console . log ( set ) ;
13
+
14
+ // ** Extra Exercise ** //
15
+ const setA : Set < number > = new Set ( [ 1 , 2 , 3 ] ) ;
16
+ const setB : Set < number > = new Set ( [ 3 , 4 , 5 ] ) ;
17
+
18
+ // Union
19
+ const union : Set < number > = new Set ( [ ...setA , ...setB ] ) ;
20
+ console . log ( union ) ;
21
+
22
+ // Intersection
23
+ const intersection : Set < number > = new Set ( [ ...setA ] . filter ( x => setB . has ( x ) ) ) ;
24
+ console . log ( intersection ) ;
25
+
26
+ // Difference
27
+ const difference : Set < number > = new Set ( [ ...setA ] . filter ( x => ! setB . has ( x ) ) ) ;
28
+ console . log ( difference ) ;
29
+
30
+ // Symmetric Difference
31
+ const symmetricDifference : Set < number > = new Set ( [
32
+ ...[ ...setA ] . filter ( x => ! setB . has ( x ) ) ,
33
+ ...[ ...setB ] . filter ( x => ! setA . has ( x ) )
34
+ ] ) ;
35
+ console . log ( symmetricDifference ) ;
You can’t perform that action at this time.
0 commit comments