From 3e1917c19c8f6526d2d7d44358f8bab82fcf0237 Mon Sep 17 00:00:00 2001 From: Lukas Wagner Date: Thu, 3 Feb 2022 13:30:20 +0100 Subject: [PATCH] fix find predicate closes #29 --- packages/csv-parser/src/types/column/baseColumn.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/csv-parser/src/types/column/baseColumn.ts b/packages/csv-parser/src/types/column/baseColumn.ts index 3483c1a..5c7a3a8 100644 --- a/packages/csv-parser/src/types/column/baseColumn.ts +++ b/packages/csv-parser/src/types/column/baseColumn.ts @@ -39,12 +39,13 @@ export abstract class BaseColumn> implements IColumn { } public get(index: number): T { - const chunk = this._chunks.find((c) => c.offset < index && c.offset + c.length >= index); + const chunk = this._chunks.find((c) => c.offset <= index && c.offset + c.length > index); if (!chunk) throw new Error('Invalid index.'); return chunk.get(index - chunk.offset); } + public set(index: number, value: T): void { - const chunk = this._chunks.find((c) => c.offset < index && c.offset + c.length >= index); + const chunk = this._chunks.find((c) => c.offset <= index && c.offset + c.length > index); if (!chunk) throw new Error('Invalid index.'); chunk.set(index - chunk.offset, value); }