Skip to content

Commit e4d2774

Browse files
committed
fix: Address round 2 code review feedback (Type scoping, SRI, Side effects)
- Snail Traversal: Fixed TypeScript generic scoping (this: T[]) and removed redundant casts. - README_react.html: Added SRI integrity hashes for React 18.3.1. - Cache With Time Limit: Added @sideeffect annotation to count().
1 parent d6c25cf commit e4d2774

4 files changed

Lines changed: 22 additions & 16 deletions

File tree

JavaScript/2622. Cache With Time Limit/Claude Code Sonnet 4.5/CacheWithTimeLimit_TS.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@
291291
" * 未期限切れキーの数を取得\n",
292292
" * @returns アクティブなキーの数\n",
293293
" * @complexity Time: O(n), Space: O(1)\n",
294+
" * @sideeffect 期限切れエントリを遅延削除する\n",
294295
" */\n",
295296
" count(): number {\n",
296297
" const now = Date.now();\n",

JavaScript/2624. Snail Traversal/Claude Code Sonnet 4.5/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ declare global {
163163
* @returns 2D配列(Snail pattern)、無効な入力の場合は空配列
164164
* @complexity Time: O(n), Space: O(n) where n = this.length
165165
*/
166-
Array.prototype.snail = function (rowsCount: number, colsCount: number): T[][] {
166+
Array.prototype.snail = function <T>(this: T[], rowsCount: number, colsCount: number): T[][] {
167167
// 入力バリデーション
168168
if (rowsCount * colsCount !== this.length) {
169169
return [];
@@ -183,7 +183,7 @@ Array.prototype.snail = function (rowsCount: number, colsCount: number): T[][] {
183183
// 偶数列: 上から下、奇数列: 下から上
184184
const row = col % 2 === 0 ? positionInCol : rowsCount - 1 - positionInCol;
185185

186-
result[row]![col] = this[i] as T;
186+
result[row]![col] = this[i];
187187
}
188188

189189
return result;
@@ -203,7 +203,7 @@ declare global {
203203
* Snail traversal(最適化版)
204204
* ビット演算と整数除算でパフォーマンス向上
205205
*/
206-
Array.prototype.snail = function (rowsCount: number, colsCount: number): T[][] {
206+
Array.prototype.snail = function <T>(this: T[], rowsCount: number, colsCount: number): T[][] {
207207
const n = this.length;
208208
if (rowsCount * colsCount !== n) return [];
209209

@@ -235,7 +235,7 @@ declare global {
235235
}
236236
}
237237

238-
Array.prototype.snail = function (rowsCount: number, colsCount: number): T[][] {
238+
Array.prototype.snail = function <T>(this: T[], rowsCount: number, colsCount: number): T[][] {
239239
const n = this.length;
240240
if (rowsCount * colsCount !== n) return [];
241241

JavaScript/2624. Snail Traversal/Claude Code Sonnet 4.5/README_react.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,10 +1144,15 @@ <h3 class="text-xl font-semibold text-teal-800 mt-8 mb-4">実装方法の比較<
11441144
</div>
11451145

11461146
<!-- React & ReactDOM -->
1147-
<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
11481147
<script
1149-
crossorigin
1150-
src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"
1148+
src="https://unpkg.com/react@18.3.1/umd/react.production.min.js"
1149+
integrity="sha384-DGyLxAyjq0f9SPpVevD6IgztCFlnMF6oW/XQGmfe+IsZ8TqEiDrcHkMLKI6fiB/Z"
1150+
crossorigin="anonymous"
1151+
></script>
1152+
<script
1153+
src="https://unpkg.com/react-dom@18.3.1/umd/react-dom.production.min.js"
1154+
integrity="sha384-gTGxhz21lVGYNMcdJOyq01Edg0jhn/c22nsx0kyqP0TxaV5WVdsSH1fSDUf5YJj1"
1155+
crossorigin="anonymous"
11511156
></script>
11521157

11531158
<!-- Babel Standalone -->

JavaScript/2624. Snail Traversal/Claude Code Sonnet 4.5/Snail_Traversal_TS.ipynb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
" * // [[1,4,5], [2,3,6]]\n",
8080
" * // 列0: [1,2](下向き), 列1: [3,4](上向き), 列2: [5,6](下向き)\n",
8181
" */\n",
82-
"Array.prototype.snail = function(rowsCount: number, colsCount: number): T[][] {\n",
82+
"Array.prototype.snail = function<T>(this: T[], rowsCount: number, colsCount: number): T[][] {\n",
8383
" // 入力バリデーション(早期リターン)\n",
8484
" if (rowsCount * colsCount !== this.length) {\n",
8585
" return [];\n",
@@ -107,7 +107,7 @@
107107
" : rowsCount - 1 - positionInCol;\n",
108108
" \n",
109109
" // 型安全な代入(this[i]はnumber型と推論される)\n",
110-
" result[row]![col] = this[i] as T;\n",
110+
" result[row]![col] = this[i];\n",
111111
" }\n",
112112
" \n",
113113
" return result;\n",
@@ -153,7 +153,7 @@
153153
"\n",
154154
"3. **null安全性**\n",
155155
" - `result[row]![col]`で非null assertion(配列境界は数学的に保証済み)\n",
156-
" - `this[i] as T`でLeetCode形式の型変換\n",
156+
" - `this[i]`でLeetCode形式の型変換\n",
157157
"\n",
158158
"### コンパイル時最適化\n",
159159
"\n",
@@ -203,7 +203,7 @@
203203
" * @returns 2D配列(Snail pattern)、無効な入力の場合は空配列\n",
204204
" * @complexity Time: O(n), Space: O(n)\n",
205205
" */\n",
206-
"Array.prototype.snail = function(rowsCount: number, colsCount: number): T[][] {\n",
206+
"Array.prototype.snail = function<T>(this: T[], rowsCount: number, colsCount: number): T[][] {\n",
207207
" // 早期リターン最適化\n",
208208
" const n = this.length;\n",
209209
" if (rowsCount * colsCount !== n) return [];\n",
@@ -220,7 +220,7 @@
220220
" const pos = i % rowsCount;\n",
221221
" const row = (col & 1) ? rowsCount - 1 - pos : pos; // col % 2の最適化\n",
222222
" \n",
223-
" result[row][col] = this[i] as T;\n",
223+
" result[row][col] = this[i];\n",
224224
" }\n",
225225
" \n",
226226
" return result;\n",
@@ -243,7 +243,7 @@
243243
" }\n",
244244
"}\n",
245245
"\n",
246-
"Array.prototype.snail = function(rowsCount: number, colsCount: number): T[][] {\n",
246+
"Array.prototype.snail = function<T>(this: T[], rowsCount: number, colsCount: number): T[][] {\n",
247247
" const n = this.length;\n",
248248
" \n",
249249
" // バリデーション統合\n",
@@ -265,7 +265,7 @@
265265
" const pos = i - col * rows; // モジュロ演算を減算に変換\n",
266266
" const row = col & 1 ? lastRow - pos : pos;\n",
267267
" \n",
268-
" result[row][col] = this[i] as T;\n",
268+
" result[row][col] = this[i];\n",
269269
" }\n",
270270
" \n",
271271
" return result;\n",
@@ -323,7 +323,7 @@
323323
"## メモリ最優先版(Memory Beats 90%+目標)\n",
324324
"\n",
325325
"```typescript\n",
326-
"Array.prototype.snail = function(rowsCount: number, colsCount: number): T[][] {\n",
326+
"Array.prototype.snail = function<T>(this: T[], rowsCount: number, colsCount: number): T[][] {\n",
327327
" if (rowsCount * colsCount !== this.length) return [];\n",
328328
" \n",
329329
" const result: T[][] = Array(rowsCount);\n",
@@ -336,7 +336,7 @@
336336
" const c = (i / rowsCount) | 0;\n",
337337
" const pos = i - c * rowsCount;\n",
338338
" const row = (c & 1) ? rowsCount - 1 - pos : pos;\n",
339-
" result[row][c] = this[i] as T;\n",
339+
" result[row][c] = this[i];\n",
340340
" }\n",
341341
" \n",
342342
" return result;\n",

0 commit comments

Comments
 (0)