Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions benchmarks/performance/pull.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('pull array size 100', () => {
const even = [...Array(50)].map((_, i) => i * 2);

bench('es-toolkit/pull', () => {
pullToolkit([...array], even);
pullToolkit([...array], ...even);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a type error, which I fixed.

});

bench('lodash/pull', () => {
Expand All @@ -23,7 +23,7 @@ describe('pull array size 1000', () => {
const even = [...Array(500)].map((_, i) => i * 2);

bench('es-toolkit/pull', () => {
pullToolkit([...array], [...even]);
pullToolkit([...array], ...even);
});

bench('lodash/pull', () => {
Expand All @@ -36,7 +36,7 @@ describe('pull array size 10000', () => {
const even = [...Array(5000)].map((_, i) => i * 2);

bench('es-toolkit/pull', () => {
pullToolkit([...array], [...even]);
pullToolkit([...array], ...even);
});

bench('lodash/pull', () => {
Expand Down
4 changes: 2 additions & 2 deletions docs/ja/reference/array/pull.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
## インターフェース

```typescript
function pull<T>(arr: T[], valuesToRemove: unknown[]): T[];
function pull<T, U extends T>(arr: T[], valuesToRemove: readonly U[]): T[];
```

### パラメータ

- `arr` (`T[]`): 変更する配列。
- `valuesToRemove` (`unknown[]`): 配列から削除する値。
- `valuesToRemove` (`U[]`): 配列から削除する値。

### 戻り値

Expand Down
4 changes: 2 additions & 2 deletions docs/ko/reference/array/pull.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
## 인터페이스

```typescript
function pull<T>(arr: T[], valuesToRemove: unknown[]): T[];
function pull<T, U extends T>(arr: T[], valuesToRemove: readonly U[]): T[];
```

### 파라미터

- `arr` (`T[]`): 수정할 배열.
- `valuesToRemove` (`unknown[]`): 배열에서 제거할 값들.
- `valuesToRemove` (`U[]`): 배열에서 제거할 값들.

### 반환 값

Expand Down
4 changes: 2 additions & 2 deletions docs/reference/array/pull.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ If you want to remove values without modifying the original array, use [differen
## Signature

```typescript
function pull<T>(arr: T[], valuesToRemove: unknown[]): T[];
function pull<T, U extends T>(arr: T[], valuesToRemove: readonly U[]): T[];
```

### Parameters

- `arr` (`T[]`): The array to modify.
- `valuesToRemove` (`unknown[]`): The values to remove from the array.
- `valuesToRemove` (`U[]`): The values to remove from the array.

### Returns

Expand Down
4 changes: 2 additions & 2 deletions docs/zh_hans/reference/array/pull.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
## 签名

```typescript
function pull<T>(arr: T[], valuesToRemove: unknown[]): T[];
function pull<T, U extends T>(arr: T[], valuesToRemove: readonly U[]): T[];
```

### 参数

- `arr` (`T[]`): 要修改的数组。
- `valuesToRemove` (`unknown[]`): 要从数组中移除的值。
- `valuesToRemove` (`U[]`): 要从数组中移除的值。

### 返回值

Expand Down
9 changes: 5 additions & 4 deletions src/array/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@
* This function changes `arr` in place.
* If you want to remove values without modifying the original array, use `difference`.
*
* @template T, U
* @template T - The type of elements in the array.
* @template U - The type of values to remove from the array.
* @param {T[]} arr - The array to modify.
* @param {unknown[]} valuesToRemove - The values to remove from the array.
* @param {U[]} valuesToRemove - The values to remove from the array.
* @returns {T[]} The modified array with the specified values removed.
*
* @example
* const numbers = [1, 2, 3, 4, 5, 2, 4];
* pull(numbers, [2, 4]);
* console.log(numbers); // [1, 3, 5]
*/
export function pull<T>(arr: T[], valuesToRemove: readonly unknown[]): T[] {
export function pull<T, U extends T>(arr: T[], valuesToRemove: readonly U[]): T[] {
const valuesSet = new Set(valuesToRemove);
let resultIndex = 0;

for (let i = 0; i < arr.length; i++) {
if (valuesSet.has(arr[i])) {
if (valuesSet.has(arr[i] as U)) {
continue;
}

Expand Down
10 changes: 5 additions & 5 deletions src/compat/array/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { pull as pullToolkit } from '../../array/pull.ts';
*
* **Note:** Unlike `_.without`, this method mutates `array`.
*
* @template T
* @template T - The type of elements in the array.
* @param {T[]} array - The array to modify.
* @param {...T[]} values - The values to remove.
* @returns {T[]} Returns `array`.
Expand All @@ -24,7 +24,7 @@ export function pull<T>(array: T[], ...values: T[]): T[];
*
* **Note:** Unlike `_.without`, this method mutates `array`.
*
* @template L
* @template L - The type of elements in the array-like object.
* @param {L} array - The array to modify.
* @param {...L[0][]} values - The values to remove.
* @returns {L} Returns `array`.
Expand All @@ -44,16 +44,16 @@ export function pull<L extends ArrayLike<any>>(array: L extends readonly any[] ?
* This function changes `arr` in place.
* If you want to remove values without modifying the original array, use `difference`.
*
* @template T, U
* @template T - The type of elements in the array.
* @param {T[]} arr - The array to modify.
* @param {...unknown[]} valuesToRemove - The values to remove from the array.
* @param {T[]} valuesToRemove - The values to remove from the array.
* @returns {T[]} The modified array with the specified values removed.
*
* @example
* const numbers = [1, 2, 3, 4, 5, 2, 4];
* pull(numbers, [2, 4]);
* console.log(numbers); // [1, 3, 5]
*/
export function pull<T>(arr: T[], ...valuesToRemove: readonly unknown[]): T[] {
export function pull<T>(arr: T[], ...valuesToRemove: readonly T[]): T[] {
return pullToolkit(arr, valuesToRemove);
}