-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
142 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# slice | ||
|
||
::: info | ||
この関数は互換性のために `es-toolkit/compat` からのみインポートできます。代替可能なネイティブ JavaScript API があるか、まだ十分に最適化されていないためです。 | ||
|
||
`es-toolkit/compat` からこの関数をインポートすると、[lodash と完全に同じように動作](../../../compatibility.md)します。 | ||
::: | ||
|
||
インデックス `start` からインデックス `end` までの `array` の部分配列を作成します。部分配列には `end` は含まれません。 | ||
|
||
基本の `Array.prototype.slice` と異なり、スパース配列に対して密な配列を返しません。 | ||
|
||
## インターフェース | ||
|
||
```typescript | ||
function slice<T>(array: T[], start?: number, end?: number): T[]; | ||
``` | ||
|
||
### パラメータ | ||
|
||
- `array` (`T[]`): 部分配列を作成する配列。 | ||
- `start` (`number`): 開始位置。デフォルトは `0` です。 | ||
- `end` (`number`): 終了位置。デフォルトは `array.length` です。 | ||
|
||
### 戻り値 | ||
|
||
(`T[]`): `array` の `start` から `end` までの部分配列。 | ||
|
||
## 例 | ||
|
||
```typescript | ||
slice([1, 2, 3], 1, 2); // => [2] | ||
slice(new Array(3)); // => [undefined, undefined, undefined] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# slice | ||
|
||
::: info | ||
이 함수는 호환성을 위한 `es-toolkit/compat` 에서만 가져올 수 있어요. 대체할 수 있는 네이티브 JavaScript API가 있거나, 아직 충분히 최적화되지 않았기 때문이에요. | ||
|
||
`es-toolkit/compat`에서 이 함수를 가져오면, [lodash와 완전히 똑같이 동작](../../../compatibility.md)해요. | ||
::: | ||
|
||
인덱스 `start`부터 인덱스 `end`까지 `array`의 부분 배열을 만들어요. 부분 배열에서 `end`는 포함하지 않아요. | ||
|
||
기본 `Array.prototype.slice`와 다르게, 희소 배열(Sparse array)에 대해 밀집 배열(Dense array)을 반환하지 않아요. | ||
|
||
## 인터페이스 | ||
|
||
```typescript | ||
function slice<T>(array: T[], start?: number, end?: number): T[]; | ||
``` | ||
|
||
### 파라미터 | ||
|
||
- `array` (`T[]`): 부분 배열을 만들 배열. | ||
- `start` (`number`): 시작 위치. 기본값은 `0`이에요. | ||
- `end` (`number`): 끝 위치. 기본값은 `array.length`예요. | ||
|
||
### 반환 값 | ||
|
||
(`T[]`): `array`의 `start`부터 `end`까지의 부분 배열. | ||
|
||
## 예시 | ||
|
||
```typescript | ||
slice([1, 2, 3], 1, 2); // => [2] | ||
slice(new Array(3)); // => [undefined, undefined, undefined] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# slice | ||
|
||
::: info | ||
This function is only available in `es-toolkit/compat` for compatibility reasons. It either has alternative native JavaScript APIs or isn’t fully optimized yet. | ||
|
||
When imported from `es-toolkit/compat`, it behaves exactly like lodash and provides the same functionalities, as detailed [here](../../../compatibility.md). | ||
::: | ||
|
||
Create a slice of `array` from `start` up to, but not including, `end`. | ||
|
||
It does not return a dense array for sparse arrays unlike the native `Array.prototype.slice`. | ||
|
||
## Signature | ||
|
||
```typescript | ||
function slice<T>(array: T[], start?: number, end?: number): T[]; | ||
``` | ||
|
||
### Parameters | ||
|
||
- `array` (`T[]`): The array to slice. | ||
- `start` (`number`): The start position. Defaults to `0`. | ||
- `end` (`number`): The end position. Defaults to `array.length`. | ||
|
||
### Returns | ||
|
||
(`T[]`): The slice of `array`. | ||
|
||
## Examples | ||
|
||
```typescript | ||
slice([1, 2, 3], 1, 2); // => [2] | ||
slice(new Array(3)); // => [undefined, undefined, undefined] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# slice | ||
|
||
::: info | ||
出于兼容性原因,此函数仅在 `es-toolkit/compat` 中提供。它可能具有替代的原生 JavaScript API,或者尚未完全优化。 | ||
|
||
从 `es-toolkit/compat` 导入时,它的行为与 lodash 完全一致,并提供相同的功能,详情请见 [这里](../../../compatibility.md)。 | ||
::: | ||
|
||
从索引 `start` 到索引 `end` 创建 `array` 的部分数组。部分数组不包含 `end`。 | ||
|
||
与基本的 `Array.prototype.slice` 不同,它不会对稀疏数组返回密集数组。 | ||
|
||
## 签名 | ||
|
||
```typescript | ||
function slice<T>(array: T[], start?: number, end?: number): T[]; | ||
``` | ||
|
||
### 参数 | ||
|
||
- `array` (`T[]`): 用于创建部分数组的数组。 | ||
- `start` (`number`): 开始位置。默认值为 `0`。 | ||
- `end` (`number`): 结束位置。默认值为 `array.length`。 | ||
|
||
### 返回值 | ||
|
||
(`T[]`): 从 `array` 的 `start` 到 `end` 的部分数组。 | ||
|
||
## 示例 | ||
|
||
```typescript | ||
slice([1, 2, 3], 1, 2); // => [2] | ||
slice(new Array(3)); // => [undefined, undefined, undefined] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters