File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed
src/course-master-the-coding/data-structures/hash-tables Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change 1
1
class HashTableMain {
2
- private data : [ ] | [ string , number | string ] [ ] [ ] = [ ] ;
2
+ public data : [ ] | [ string , number | string ] [ ] [ ] = [ ] ;
3
3
constructor ( size : number ) {
4
4
this . data = new Array ( size ) ;
5
5
}
@@ -40,6 +40,23 @@ class HashTableMain {
40
40
}
41
41
return undefined ;
42
42
}
43
+
44
+ /**
45
+ * keys
46
+ */
47
+ public keys ( ) : ( number | string ) [ ] {
48
+ const keysArray : ( number | string ) [ ] = [ ] ;
49
+ console . log ( this . data . length ) ;
50
+ for ( let i = 0 ; i < this . data . length ; i ++ ) {
51
+ console . log ( this . data [ i ] ) ;
52
+ if ( this . data [ i ] ) {
53
+ console . log ( this . data [ i ] [ 0 ] ) ;
54
+ console . log ( this . data [ i ] [ 0 ] [ 0 ] ) ;
55
+ keysArray . push ( this . data [ i ] [ 0 ] [ 0 ] ) ;
56
+ }
57
+ }
58
+ return keysArray ;
59
+ }
43
60
}
44
61
45
62
// Example
@@ -50,3 +67,5 @@ myHashTable01.set('apples', 9);
50
67
myHashTable01 . get ( 'apples' ) ;
51
68
myHashTable01 . set ( 'banana' , 'Nice foots' ) ;
52
69
myHashTable01 . get ( 'banana' ) ;
70
+ myHashTable01 . keys ( ) ;
71
+ console . log ( myHashTable01 . data ) ;
You can’t perform that action at this time.
0 commit comments