{"record":{"id":"e19a4509f786c0d8","repo":"krahets/hello-algo","slug":"error-e19a45","errorCode":null,"errorMessage":"индекс выходит за границы","messagePattern":"индекс выходит за границы","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ru/codes/typescript/chapter_array_and_linkedlist/my_list.ts","lineNumber":32,"sourceCode":"    /* Конструктор */\n    constructor() {\n        this.arr = new Array(this._capacity);\n    }\n\n    /* Получить длину списка (текущее число элементов) */\n    public size(): number {\n        return this._size;\n    }\n\n    /* Получить вместимость списка */\n    public capacity(): number {\n        return this._capacity;\n    }\n\n    /* Доступ к элементу */\n    public get(index: number): number {\n        // Если индекс выходит за границы, выбрасывается исключение; далее аналогично\n        if (index < 0 || index >= this._size) throw new Error('индекс выходит за границы');\n        return this.arr[index];\n    }\n\n    /* Обновление элемента */\n    public set(index: number, num: number): void {\n        if (index < 0 || index >= this._size) throw new Error('индекс выходит за границы');\n        this.arr[index] = num;\n    }\n\n    /* Добавление элемента в конец */\n    public add(num: number): void {\n        // Если длина равна вместимости, требуется расширение\n        if (this._size === this._capacity) this.extendCapacity();\n        // Добавить новый элемент в конец списка\n        this.arr[this._size] = num;\n        this._size++;\n    }\n","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ru/codes/typescript/chapter_array_and_linkedlist/my_list.ts#L14-L50","documentation":"Thrown by MyList.get (TS) with message 'индекс выходит за границы' ('index out of bounds') when the requested index is negative or >= the logical size (_size), distinct from the underlying array's capacity. The list tracks a logical length shorter than the backing array, so capacity is not the bound.","triggerScenarios":"Calling get(index) with index < 0 or index >= this._size. Indices in [_size, _capacity) are reserved/unused and also throw.","commonSituations":"Off-by-one loops (<= vs <); using the backing array length or capacity as the loop bound instead of size(); reading an index after a remove shifted elements.","solutions":["Loop with j < list.size(), not <=, and never use capacity() as the bound.","Re-read size() after structural changes before indexing.","Validate: if (i >= 0 && i < list.size()) list.get(i)."],"exampleFix":"// before\nfor (let i = 0; i <= list.size(); i++) list.get(i); // last throws\n\n// after\nfor (let i = 0; i < list.size(); i++) list.get(i);","handlingStrategy":"validation","validationCode":"function safeGet(list, i) {\n  if (i < 0 || i >= list.size()) throw new RangeError('bad index');\n  return list.get(i);\n}","typeGuard":"function isIndexInBounds(i, list) {\n  return Number.isInteger(i) && i >= 0 && i < list.size();\n}","tryCatchPattern":null,"preventionTips":["Loop with i < list.size(), not <=.","Never use capacity() as a loop bound — it exceeds the logical size.","Re-read size() after structural modifications before indexing."],"tags":["array","list","typescript","precondition","range","off-by-one","hello-algo"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}