Skip to content

Commit

Permalink
fix(at, pullAt): Return T[] instead of Array<T | undefined>
Browse files Browse the repository at this point in the history
  • Loading branch information
raon0211 committed Jan 30, 2025
1 parent e4fb039 commit e407e15
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions docs/ja/reference/array/at.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
## インターフェース

```typescript
function at<T>(arr: T[], indices: number[]): Array<T | undefined>;
function at<T>(arr: T[], indices: number[]): T[];
```

### パラメータ
Expand All @@ -17,7 +17,7 @@ function at<T>(arr: T[], indices: number[]): Array<T | undefined>;

### 戻り値

(`Array<T | undefined>`): 指定されたインデックスの位置にある要素を含む新しい配列。
(`T[]`): 指定されたインデックスの位置にある要素を含む新しい配列。

##

Expand Down
4 changes: 2 additions & 2 deletions docs/ja/reference/array/pullAt.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
## インターフェース

```typescript
function pullAt<T>(arr: T[], indicesToRemove: number[]): Array<T | undefined>;
function pullAt<T>(arr: T[], indicesToRemove: number[]): T[];
```

### パラメータ
Expand All @@ -17,7 +17,7 @@ function pullAt<T>(arr: T[], indicesToRemove: number[]): Array<T | undefined>;

### 戻り値

(`Array<T | undefined>`): 元の配列から削除された要素を含む新しい配列。
(`T[]`): 元の配列から削除された要素を含む新しい配列。

##

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

```typescript
function at<T>(arr: T[], indices: number[]): Array<T | undefined>;
function at<T>(arr: T[], indices: number[]): T[];
```

### 파라미터
Expand All @@ -17,7 +17,7 @@ function at<T>(arr: T[], indices: number[]): Array<T | undefined>;

### 반환 값

(`Array<T | undefined>`): 주어진 인덱스에 있는 요소들을 가지는 새 배열.
(`T[]`): 주어진 인덱스에 있는 요소들을 가지는 새 배열.

## 예시

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

```typescript
function pullAt<T>(arr: T[], indicesToRemove: number[]): Array<T | undefined>;
function pullAt<T>(arr: T[], indicesToRemove: number[]): T[];
```

### 파라미터
Expand All @@ -17,7 +17,7 @@ function pullAt<T>(arr: T[], indicesToRemove: number[]): Array<T | undefined>;

### 반환 값

(`Array<T | undefined>`): 제거된 요소들의 배열.
(`T[]`): 제거된 요소들의 배열.

## 예시

Expand Down
4 changes: 2 additions & 2 deletions docs/reference/array/at.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This function supports negative indices, which count from the end of the array.
## Signature

```typescript
function at<T>(arr: T[], indices: number[]): Array<T | undefined>;
function at<T>(arr: T[], indices: number[]): T[];
```

### Parameters
Expand All @@ -17,7 +17,7 @@ function at<T>(arr: T[], indices: number[]): Array<T | undefined>;

### Returns

(`Array<T | undefined>`): A new array containing the elements at the specified indices.
(`T[]`): A new array containing the elements at the specified indices.

## Examples

Expand Down
4 changes: 2 additions & 2 deletions docs/reference/array/pullAt.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This function supports negative indices, which count from the end of the array.
## Signature

```typescript
function pullAt<T>(arr: T[], indicesToRemove: number[]): Array<T | undefined>;
function pullAt<T>(arr: T[], indicesToRemove: number[]): T[];
```

### Parameters
Expand All @@ -17,7 +17,7 @@ function pullAt<T>(arr: T[], indicesToRemove: number[]): Array<T | undefined>;

### Returns

(`Array<T | undefined>`): An array containing the elements that were removed from the original array.
(`T[]`): An array containing the elements that were removed from the original array.

## Examples

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

```typescript
function at<T>(arr: T[], indices: number[]): Array<T | undefined>;
function at<T>(arr: T[], indices: number[]): T[];
```

### 参数
Expand All @@ -17,7 +17,7 @@ function at<T>(arr: T[], indices: number[]): Array<T | undefined>;

### 返回值

(`Array<T | undefined>`): 一个新数组,包含在指定索引处的元素。
(`T[]`): 一个新数组,包含在指定索引处的元素。

## 示例

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

```typescript
function pullAt<T>(arr: T[], indicesToRemove: number[]): Array<T | undefined>;
function pullAt<T>(arr: T[], indicesToRemove: number[]): T[];
```

### 参数
Expand All @@ -17,7 +17,7 @@ function pullAt<T>(arr: T[], indicesToRemove: number[]): Array<T | undefined>;

### 返回值

(`Array<T | undefined>`): 包含从原始数组中删除的元素的新数组。
(`T[]`): 包含从原始数组中删除的元素的新数组。

## 示例

Expand Down
4 changes: 2 additions & 2 deletions src/array/at.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* const result = at(numbers, [1, 3, 4]);
* console.log(result); // [20, 40, 50]
*/
export function at<T>(arr: readonly T[], indices: number[]): Array<T | undefined> {
const result = new Array<T | undefined>(indices.length);
export function at<T>(arr: readonly T[], indices: number[]): T[] {
const result = new Array<T>(indices.length);
const length = arr.length;

for (let i = 0; i < indices.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/array/pullAt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { at } from './at.ts';
* console.log(removed); // [20, 40, 50]
* console.log(numbers); // [10, 30]
*/
export function pullAt<T>(arr: T[], indicesToRemove: number[]): Array<T | undefined> {
export function pullAt<T>(arr: T[], indicesToRemove: number[]): T[] {
const removed = at(arr, indicesToRemove);
const indices = new Set(indicesToRemove.slice().sort((x, y) => y - x));

Expand Down

0 comments on commit e407e15

Please sign in to comment.