|
2 | 2 |
|
3 | 3 | type NumIndexedObject = { [index: number]: any };
|
4 | 4 |
|
5 |
| -class MyArray<T> { |
| 5 | +export class MyArray<T> { |
6 | 6 |
|
7 | 7 | public length: number;
|
8 | 8 | private data: NumIndexedObject;
|
@@ -83,39 +83,43 @@ class MyArray {
|
83 | 83 |
|
84 | 84 |
|
85 | 85 |
|
86 |
| -let helloArray = new MyArray<string>(); |
| 86 | +//--------------------------------------------------------------------- |
| 87 | +// ---------- MAIN PROGRAM ---------- |
| 88 | +//--------------------------------------------------------------------- |
| 89 | +if (import.meta.main) { |
87 | 90 |
|
88 |
| -helloArray.push('Hello'); // O(1) |
89 |
| -helloArray.push('world'); |
90 |
| -console.log(helloArray); |
| 91 | + let helloArray = new MyArray<string>(); |
91 | 92 |
|
92 |
| -helloArray.pop(); // O(1) |
93 |
| -console.log(helloArray); |
| 93 | + helloArray.push('Hello'); // O(1) |
| 94 | + helloArray.push('world'); |
| 95 | + console.log(helloArray); |
94 | 96 |
|
95 |
| -helloArray.push('Deno'); |
96 |
| -helloArray.push('!'); |
97 |
| -console.log(helloArray); |
| 97 | + helloArray.pop(); // O(1) |
| 98 | + console.log(helloArray); |
98 | 99 |
|
99 |
| -console.log('At index 2:', helloArray.get(2)); |
| 100 | + helloArray.push('Deno'); |
| 101 | + helloArray.push('!'); |
| 102 | + console.log(helloArray); |
100 | 103 |
|
101 |
| -// ------------------------------------------- |
| 104 | + console.log('At index 2:', helloArray.get(2)); |
102 | 105 |
|
103 |
| -let sokka = new MyArray<string>(); |
| 106 | + // ------------------------------------------- |
104 | 107 |
|
105 |
| -sokka.push('s'); |
106 |
| -sokka.push('o'); |
107 |
| -sokka.push('c'); |
108 |
| -sokka.push('k'); |
109 |
| -sokka.push('a'); |
110 |
| -console.log(sokka); |
| 108 | + let sokka = new MyArray<string>(); |
111 | 109 |
|
112 |
| -console.log('Element deleted:', sokka.deleteIndex(2)); // O(n) |
113 |
| -console.log(sokka); |
114 |
| - |
115 |
| -sokka.insertItemAtIndex(2, 'k'); // O(n) |
116 |
| -console.log(sokka); |
| 110 | + sokka.push('s'); |
| 111 | + sokka.push('o'); |
| 112 | + sokka.push('c'); |
| 113 | + sokka.push('k'); |
| 114 | + sokka.push('a'); |
| 115 | + console.log(sokka); |
117 | 116 |
|
| 117 | + console.log('Element deleted:', sokka.deleteIndex(2)); // O(n) |
| 118 | + console.log(sokka); |
118 | 119 |
|
| 120 | + sokka.insertItemAtIndex(2, 'k'); // O(n) |
| 121 | + console.log(sokka); |
| 122 | +} |
119 | 123 |
|
120 | 124 | // --------------------------- Terminal Output: ---------------------------
|
121 | 125 | // MyArray { length: 2, data: { 0: "Hello", 1: "world" } }
|
|
0 commit comments