From d3c02eaca39e7b863f514a3dd4af23d8aa10e65c Mon Sep 17 00:00:00 2001 From: eunwoo-levi Date: Wed, 11 Feb 2026 17:22:51 +0900 Subject: [PATCH 1/3] fix(pullAt): resolve incorrect element removal with negative indices --- src/array/pullAt.spec.ts | 24 ++++++++++++++++++++++++ src/array/pullAt.ts | 4 +++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/array/pullAt.spec.ts b/src/array/pullAt.spec.ts index f9220ce524..0315298c85 100644 --- a/src/array/pullAt.spec.ts +++ b/src/array/pullAt.spec.ts @@ -50,6 +50,30 @@ describe('pullAt', () => { expect(actual).toEqual([2, 4, 12, 8, 6, 10]); }); + it('should work with a single negative index', () => { + const array = [10, 20, 30, 40, 50]; + const result = pullAt(array, [-1]); + + expect(array).toEqual([10, 20, 30, 40]); + expect(result).toEqual([50]); + }); + + it('should work with multiple negative indices', () => { + const array = [10, 20, 30, 40, 50]; + const result = pullAt(array, [-1, -2]); + + expect(array).toEqual([10, 20, 30]); + expect(result).toEqual([50, 40]); + }); + + it('should work with mixed positive and negative indices', () => { + const array = [10, 20, 30, 40, 50]; + const result = pullAt(array, [0, -1]); + + expect(array).toEqual([20, 30, 40]); + expect(result).toEqual([10, 50]); + }); + it('should work with objects', () => { const foo = { foo: 1 }; const bar = { foo: 2 }; diff --git a/src/array/pullAt.ts b/src/array/pullAt.ts index 485f46b099..625675c902 100644 --- a/src/array/pullAt.ts +++ b/src/array/pullAt.ts @@ -18,7 +18,9 @@ import { at } from './at.ts'; */ export function pullAt(arr: T[], indicesToRemove: number[]): T[] { const removed = at(arr, indicesToRemove); - const indices = new Set(indicesToRemove.slice().sort((x, y) => y - x)); + + const normalizedIndices = indicesToRemove.map(index => (index < 0 ? arr.length + index : index)); + const indices = new Set(normalizedIndices.slice().sort((x, y) => y - x)); for (const index of indices) { arr.splice(index, 1); From 4d4c050023ee637068b79f2c157eefd2b4679e1c Mon Sep 17 00:00:00 2001 From: Sojin Park Date: Sun, 16 Aug 2026 15:39:05 +0900 Subject: [PATCH 2/3] refactor(pullAt): normalize indices inline instead of a separate variable --- src/array/pullAt.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/array/pullAt.ts b/src/array/pullAt.ts index 625675c902..8d34973054 100644 --- a/src/array/pullAt.ts +++ b/src/array/pullAt.ts @@ -18,9 +18,9 @@ import { at } from './at.ts'; */ export function pullAt(arr: T[], indicesToRemove: number[]): T[] { const removed = at(arr, indicesToRemove); - - const normalizedIndices = indicesToRemove.map(index => (index < 0 ? arr.length + index : index)); - const indices = new Set(normalizedIndices.slice().sort((x, y) => y - x)); + const indices = new Set( + indicesToRemove.map(index => (index < 0 ? index + arr.length : index)).sort((x, y) => y - x) + ); for (const index of indices) { arr.splice(index, 1); From 0b51259e670d76d0c89d5110c78f8f9b2479c7b5 Mon Sep 17 00:00:00 2001 From: Sojin Park Date: Sun, 16 Aug 2026 15:56:08 +0900 Subject: [PATCH 3/3] style(pullAt): format indices chain to satisfy prettier --- src/array/pullAt.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/array/pullAt.ts b/src/array/pullAt.ts index efea5f34cc..ed33bc8584 100644 --- a/src/array/pullAt.ts +++ b/src/array/pullAt.ts @@ -18,9 +18,7 @@ import { at } from './at.ts'; */ export function pullAt(arr: T[], indicesToRemove: readonly number[]): T[] { const removed = at(arr, indicesToRemove); - const indices = new Set( - indicesToRemove.map(index => (index < 0 ? index + arr.length : index)).sort((x, y) => y - x) - ); + const indices = new Set(indicesToRemove.map(index => (index < 0 ? index + arr.length : index)).sort((x, y) => y - x)); for (const index of indices) { arr.splice(index, 1);