From 74b7879d1ab6bd0c7efe1b0e05173dac28ccd672 Mon Sep 17 00:00:00 2001 From: GAURAV singh Date: Thu, 25 Jun 2026 01:07:56 +0530 Subject: [PATCH 1/2] BUGFIX: add off-by-one error --- src/array.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/array.js diff --git a/src/array.js b/src/array.js new file mode 100644 index 0000000..9bd6b1e --- /dev/null +++ b/src/array.js @@ -0,0 +1,7 @@ +function getFirstN(items, n) { + let result = []; + for (let i = 0; i <= n; i++) { + result.push(items[i]); + } + return result; +} From 04f0ddfb5005f9f49cc3f4f26726475e5feca9e5 Mon Sep 17 00:00:00 2001 From: GAURAV singh Date: Thu, 25 Jun 2026 01:18:08 +0530 Subject: [PATCH 2/2] Apply AI-generated fixes - src/array.js: Fixed the loop condition to prevent accessing out of bounds of the items array. --- src/array.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array.js b/src/array.js index 9bd6b1e..c37163c 100644 --- a/src/array.js +++ b/src/array.js @@ -1,6 +1,6 @@ function getFirstN(items, n) { let result = []; - for (let i = 0; i <= n; i++) { + for (let i = 0; i < n && i < items.length; i++) { result.push(items[i]); } return result;