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
30 changes: 25 additions & 5 deletions docs/ja/reference/array/orderBy.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# orderBy

複数の基準と並び順に従って、オブジェクト配列をソートした新しい配列を返します
複数の基準と並び順に従って、配列をソートした新しい配列を返します

```typescript
const sorted = orderBy(arr, criteria, orders);
Expand All @@ -10,11 +10,31 @@ const sorted = orderBy(arr, criteria, orders);

### `orderBy(arr, criteria, orders)`

オブジェクト配列を複数の条件で複合ソートしたい場合は `orderBy` を使用してください。各条件ごとに昇順または降順を指定でき、前の条件で同じ値の場合は次の条件でソートします。
配列を複数の条件で複合ソートしたい場合は `orderBy` を使用してください。各条件ごとに昇順または降順を指定でき、前の条件で同じ値の場合は次の条件でソートします。

```typescript
import { orderBy } from 'es-toolkit/array';

// 文字列配列をソート
const strings = ['banana', 'apple', 'cherry'];
orderBy(strings, [], ['desc']);
// Returns: ['cherry', 'banana', 'apple']

// 文字列を長さでソート
const strings = ['banana', 'a', 'cherry'];
orderBy(strings, [x => x.length], ['asc']);
// Returns: ['a', 'cherry', 'banana']

// 大文字小文字を区別せずにソート
const strings = ['Banana', 'apple', 'Cherry'];
orderBy(strings, [x => x.toLowerCase()], ['asc']);
// Returns: ['apple', 'Banana', 'Cherry']

// 数値配列をソート
const numbers = [3, 1, 4, 1, 5, 9];
orderBy(numbers, [], ['desc']);
// Returns: [9, 5, 4, 3, 1, 1]

// 複数の基準でユーザー配列をソートします。
const users = [
{ user: 'fred', age: 48 },
Expand Down Expand Up @@ -60,9 +80,9 @@ orderBy(data, ['a', 'b', 'c'], ['asc', 'desc']);

#### パラメータ

- `arr` (`T[]`): ソートするオブジェクト配列です
- `criteria` (`Array<((item: T) => unknown) | keyof T>`): ソートする基準です。オブジェクトのプロパティ名または値を返す関数を使用できます。
- `orders` (`Array<'asc' | 'desc'>`): 各基準に対する並び順の配列です。`'asc'`は昇順、`'desc'`は降順を意味します。
- `arr` (`readonly T[]`): ソートする配列です
- `criteria` (`Array<((item: T) => unknown) | keyof T>`, オプション): ソートする基準です。オブジェクトのプロパティ名または値を返す関数を使用できます。指定しないか空配列の場合、プリミティブ型の値そのものでソートします
- `orders` (`Array<'asc' | 'desc'>`, オプション): 各基準に対する並び順の配列です。`'asc'`は昇順、`'desc'`は降順を意味します。デフォルトは `['asc']` です

#### 戻り値

Expand Down
37 changes: 27 additions & 10 deletions docs/ja/reference/array/sortBy.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# sortBy

与えられた基準に従ってオブジェクト配列を昇順にソートした新しい配列を返します
与えられた基準に従って配列を昇順にソートした新しい配列を返します

```typescript
const sorted = sortBy(arr, criteria);
Expand All @@ -10,11 +10,31 @@ const sorted = sortBy(arr, criteria);

### `sortBy(arr, criteria)`

オブジェクト配列を複数のプロパティまたは計算された値を基準にソートしたい場合は `sortBy` を使用してください。プロパティ名または変換関数を配列で提供すると、その順序で優先順位を付けて昇順にソートします。テーブルデータをソートしたり、複雑なソートロジックが必要なときに便利です。
配列を複数のプロパティまたは計算された値を基準にソートしたい場合は `sortBy` を使用してください。プロパティ名または変換関数を配列で提供すると、その順序で優先順位を付けて昇順にソートします。テーブルデータをソートしたり、複雑なソートロジックが必要なときに便利です。

```typescript
import { sortBy } from 'es-toolkit/array';

// 文字列配列をソート
const strings = ['banana', 'apple', 'cherry'];
sortBy(strings);
// Returns: ['apple', 'banana', 'cherry']

// 文字列を長さでソート
const strings = ['banana', 'a', 'cherry'];
sortBy(strings, [x => x.length]);
// Returns: ['a', 'cherry', 'banana']

// 大文字小文字を区別せずにソート
const strings = ['Banana', 'apple', 'Cherry'];
sortBy(strings, [x => x.toLowerCase()]);
// Returns: ['apple', 'Banana', 'Cherry']

// 数値配列をソート
const numbers = [3, 1, 4, 1, 5, 9];
sortBy(numbers);
// Returns: [1, 1, 3, 4, 5, 9]

// 単一のプロパティでソートします。
const users = [
{ name: 'john', age: 30 },
Expand Down Expand Up @@ -55,23 +75,20 @@ const products = [

const sorted = sortBy(products, [
'category',
item => -item.price, // 価格は降順で
item => -item.price, // 価格は降順で(負数変換)
]);
// Returns: カテゴリが最初、次に価格の高い順でソート

// 計算された値でソートします。
const words = ['hello', 'a', 'wonderful', 'world'];
const byLength = sortBy(
words.map(word => ({ word, length: word.length })),
['length']
);
// Returns: 文字列の長さ順でソートされたオブジェクト配列
const byLength = sortBy(words, [word => word.length]);
// Returns: ['a', 'hello', 'world', 'wonderful']
```

#### パラメータ

- `arr` (`readonly T[]`): ソートするオブジェクト配列です
- `criteria` (`Array<((item: T) => unknown) | keyof T>`): ソート基準です。オブジェクトのプロパティ名または変換関数の配列で、前にある基準が優先順位が高くなります。
- `arr` (`readonly T[]`): ソートする配列です
- `criteria` (`Array<((item: T) => unknown) | keyof T>`, オプション): ソート基準です。オブジェクトのプロパティ名または変換関数の配列で、前にある基準が優先順位が高くなります。指定しないか空配列の場合、プリミティブ型の値そのものでソートします

#### 戻り値

Expand Down
30 changes: 25 additions & 5 deletions docs/ko/reference/array/orderBy.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# orderBy

여러 기준과 정렬 방향에 따라 객체 배열을 정렬한 새 배열을 반환해요.
여러 기준과 정렬 방향에 따라 배열을 정렬한 새 배열을 반환해요.

```typescript
const sorted = orderBy(arr, criteria, orders);
Expand All @@ -10,11 +10,31 @@ const sorted = orderBy(arr, criteria, orders);

### `orderBy(arr, criteria, orders)`

객체 배열을 여러 조건으로 복합 정렬하고 싶을 때 `orderBy`를 사용하세요. 각 조건마다 오름차순이나 내림차순을 지정할 수 있고, 앞의 조건에서 같은 값이면 다음 조건으로 정렬해요.
배열을 여러 조건으로 복합 정렬하고 싶을 때 `orderBy`를 사용하세요. 각 조건마다 오름차순이나 내림차순을 지정할 수 있고, 앞의 조건에서 같은 값이면 다음 조건으로 정렬해요.

```typescript
import { orderBy } from 'es-toolkit/array';

// 문자열 배열 정렬하기
const strings = ['banana', 'apple', 'cherry'];
orderBy(strings, [], ['desc']);
// Returns: ['cherry', 'banana', 'apple']

// 문자열을 길이로 정렬하기
const strings = ['banana', 'a', 'cherry'];
orderBy(strings, [x => x.length], ['asc']);
// Returns: ['a', 'cherry', 'banana']

// 대소문자 구분 없이 정렬하기
const strings = ['Banana', 'apple', 'Cherry'];
orderBy(strings, [x => x.toLowerCase()], ['asc']);
// Returns: ['apple', 'Banana', 'Cherry']

// 숫자 배열 정렬하기
const numbers = [3, 1, 4, 1, 5, 9];
orderBy(numbers, [], ['desc']);
// Returns: [9, 5, 4, 3, 1, 1]

// 여러 기준으로 사용자 배열을 정렬해요.
const users = [
{ user: 'fred', age: 48 },
Expand Down Expand Up @@ -60,9 +80,9 @@ orderBy(data, ['a', 'b', 'c'], ['asc', 'desc']);

#### 파라미터

- `arr` (`T[]`): 정렬할 객체 배열이에요.
- `criteria` (`Array<((item: T) => unknown) | keyof T>`): 정렬할 기준들이에요. 객체의 속성 이름이나 값을 반환하는 함수를 사용할 수 있어요.
- `orders` (`Array<'asc' | 'desc'>`): 각 기준에 대한 정렬 방향 배열이에요. `'asc'`는 오름차순, `'desc'`는 내림차순을 의미해요.
- `arr` (`readonly T[]`): 정렬할 배열이에요.
- `criteria` (`Array<((item: T) => unknown) | keyof T>`, optional): 정렬할 기준들이에요. 객체의 속성 이름이나 값을 반환하는 함수를 사용할 수 있어요. 제공하지 않거나 빈 배열이면 원시 타입을 그 자체로 정렬해요.
- `orders` (`Array<'asc' | 'desc'>`, optional): 각 기준에 대한 정렬 방향 배열이에요. `'asc'`는 오름차순, `'desc'`는 내림차순을 의미해요. 기본값은 `['asc']`예요.

#### 반환 값

Expand Down
37 changes: 27 additions & 10 deletions docs/ko/reference/array/sortBy.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# sortBy

주어진 기준에 따라 객체 배열을 오름차순으로 정렬한 새 배열을 반환해요.
주어진 기준에 따라 배열을 오름차순으로 정렬한 새 배열을 반환해요.

```typescript
const sorted = sortBy(arr, criteria);
Expand All @@ -10,11 +10,31 @@ const sorted = sortBy(arr, criteria);

### `sortBy(arr, criteria)`

객체 배열을 여러 속성이나 계산된 값을 기준으로 정렬하고 싶을 때 `sortBy`를 사용하세요. 속성 이름이나 변환 함수를 배열로 제공하면, 해당 순서대로 우선순위를 두고 오름차순으로 정렬해요. 테이블 데이터를 정렬하거나 복잡한 정렬 로직이 필요할 때 유용해요.
배열을 여러 속성이나 계산된 값을 기준으로 정렬하고 싶을 때 `sortBy`를 사용하세요. 속성 이름이나 변환 함수를 배열로 제공하면, 해당 순서대로 우선순위를 두고 오름차순으로 정렬해요. 테이블 데이터를 정렬하거나 복잡한 정렬 로직이 필요할 때 유용해요.

```typescript
import { sortBy } from 'es-toolkit/array';

// 문자열 배열 정렬하기
const strings = ['banana', 'apple', 'cherry'];
sortBy(strings);
// Returns: ['apple', 'banana', 'cherry']

// 문자열을 길이로 정렬하기
const strings = ['banana', 'a', 'cherry'];
sortBy(strings, [x => x.length]);
// Returns: ['a', 'cherry', 'banana']

// 대소문자 구분 없이 정렬하기
const strings = ['Banana', 'apple', 'Cherry'];
sortBy(strings, [x => x.toLowerCase()]);
// Returns: ['apple', 'Banana', 'Cherry']

// 숫자 배열 정렬하기
const numbers = [3, 1, 4, 1, 5, 9];
sortBy(numbers);
// Returns: [1, 1, 3, 4, 5, 9]

// 단일 속성으로 정렬해요.
const users = [
{ name: 'john', age: 30 },
Expand Down Expand Up @@ -55,23 +75,20 @@ const products = [

const sorted = sortBy(products, [
'category',
item => -item.price, // 가격은 내림차순으로
item => -item.price, // 가격은 내림차순으로 (음수 변환)
]);
// Returns: 카테고리 먼저, 그 다음 가격 높은 순으로 정렬

// 계산된 값으로 정렬해요.
const words = ['hello', 'a', 'wonderful', 'world'];
const byLength = sortBy(
words.map(word => ({ word, length: word.length })),
['length']
);
// Returns: 문자열 길이 순으로 정렬된 객체 배열
const byLength = sortBy(words, [word => word.length]);
// Returns: ['a', 'hello', 'world', 'wonderful']
```

#### 파라미터

- `arr` (`readonly T[]`): 정렬할 객체 배열이에요.
- `criteria` (`Array<((item: T) => unknown) | keyof T>`): 정렬 기준이에요. 객체 속성 이름이나 변환 함수의 배열로, 앞에 있는 기준이 우선순위가 높아요.
- `arr` (`readonly T[]`): 정렬할 배열이에요.
- `criteria` (`Array<((item: T) => unknown) | keyof T>`, optional): 정렬 기준이에요. 객체 속성 이름이나 변환 함수의 배열로, 앞에 있는 기준이 우선순위가 높아요. 제공하지 않거나 빈 배열이면 원시 타입을 그 자체로 정렬해요.

#### 반환 값

Expand Down
28 changes: 24 additions & 4 deletions docs/reference/array/orderBy.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,31 @@ const sorted = orderBy(arr, criteria, orders);

### `orderBy(arr, criteria, orders)`

Use `orderBy` when you want to perform compound sorting on an array of objects with multiple conditions. You can specify ascending or descending order for each criterion, and if values are the same for the first criterion, it sorts by the next criterion.
Use `orderBy` when you want to perform compound sorting on an array with multiple conditions. You can specify ascending or descending order for each criterion, and if values are the same for the first criterion, it sorts by the next criterion.

```typescript
import { orderBy } from 'es-toolkit/array';

// Sort an array of strings
const strings = ['banana', 'apple', 'cherry'];
orderBy(strings, [], ['desc']);
// Returns: ['cherry', 'banana', 'apple']

// Sort strings by length
const strings = ['banana', 'a', 'cherry'];
orderBy(strings, [x => x.length], ['asc']);
// Returns: ['a', 'cherry', 'banana']

// Sort strings case-insensitively
const strings = ['Banana', 'apple', 'Cherry'];
orderBy(strings, [x => x.toLowerCase()], ['asc']);
// Returns: ['apple', 'Banana', 'Cherry']

// Sort an array of numbers
const numbers = [3, 1, 4, 1, 5, 9];
orderBy(numbers, [], ['desc']);
// Returns: [9, 5, 4, 3, 1, 1]

// Sort a user array by multiple criteria.
const users = [
{ user: 'fred', age: 48 },
Expand Down Expand Up @@ -60,9 +80,9 @@ orderBy(data, ['a', 'b', 'c'], ['asc', 'desc']);

#### Parameters

- `arr` (`T[]`): The array of objects to sort.
- `criteria` (`Array<((item: T) => unknown) | keyof T>`): The criteria to sort by. You can use property names of objects or functions that return values.
- `orders` (`Array<'asc' | 'desc'>`): An array of sort directions for each criterion. `'asc'` means ascending order, `'desc'` means descending order.
- `arr` (`readonly T[]`): The array to sort.
- `criteria` (`Array<((item: T) => unknown) | keyof T>`, optional): The criteria to sort by. You can use property names of objects or functions that return values. If not provided or empty, sorts primitives by their own values.
- `orders` (`Array<'asc' | 'desc'>`, optional): An array of sort directions for each criterion. `'asc'` means ascending order, `'desc'` means descending order. Defaults to `['asc']`.

#### Returns

Expand Down
35 changes: 26 additions & 9 deletions docs/reference/array/sortBy.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,31 @@ const sorted = sortBy(arr, criteria);

### `sortBy(arr, criteria)`

Use `sortBy` when you want to sort an array of objects by multiple properties or computed values. Provide property names or transformation functions as an array, and it sorts in ascending order with priority in that order. It's useful for sorting table data or when complex sorting logic is needed.
Use `sortBy` when you want to sort an array by multiple properties or computed values. Provide property names or transformation functions as an array, and it sorts in ascending order with priority in that order. It's useful for sorting table data or when complex sorting logic is needed.

```typescript
import { sortBy } from 'es-toolkit/array';

// Sort an array of strings
const strings = ['banana', 'apple', 'cherry'];
sortBy(strings);
// Returns: ['apple', 'banana', 'cherry']

// Sort strings by length
const strings = ['banana', 'a', 'cherry'];
sortBy(strings, [x => x.length]);
// Returns: ['a', 'cherry', 'banana']

// Sort strings case-insensitively
const strings = ['Banana', 'apple', 'Cherry'];
sortBy(strings, [x => x.toLowerCase()]);
// Returns: ['apple', 'Banana', 'Cherry']

// Sort an array of numbers
const numbers = [3, 1, 4, 1, 5, 9];
sortBy(numbers);
// Returns: [1, 1, 3, 4, 5, 9]

// Sort by a single property.
const users = [
{ name: 'john', age: 30 },
Expand Down Expand Up @@ -55,23 +75,20 @@ const products = [

const sorted = sortBy(products, [
'category',
item => -item.price, // Sort price in descending order
item => -item.price, // Sort price in descending order (negative conversion)
]);
// Returns: Sort by category first, then by highest price

// Sort by computed values.
const words = ['hello', 'a', 'wonderful', 'world'];
const byLength = sortBy(
words.map(word => ({ word, length: word.length })),
['length']
);
// Returns: Array of objects sorted by string length
const byLength = sortBy(words, [word => word.length]);
// Returns: ['a', 'hello', 'world', 'wonderful']
```

#### Parameters

- `arr` (`readonly T[]`): The array of objects to sort.
- `criteria` (`Array<((item: T) => unknown) | keyof T>`): Sorting criteria. An array of object property names or transformation functions, with earlier criteria having higher priority.
- `arr` (`readonly T[]`): The array to sort.
- `criteria` (`Array<((item: T) => unknown) | keyof T>`, optional): Sorting criteria. An array of object property names or transformation functions, with earlier criteria having higher priority. If not provided or empty, sorts primitives by their own values.

#### Returns

Expand Down
Loading