Skip to content

Commit 0eaf0e7

Browse files
committed
docs: update intersectionBy documentation to support multiple arrays
1 parent bb5b6f6 commit 0eaf0e7

File tree

4 files changed

+76
-20
lines changed

4 files changed

+76
-20
lines changed

docs/ja/reference/array/intersectionBy.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# intersectionBy
22

3-
変換関数の結果を基準に、2つの配列の交集合を求めた新しい配列を返します
3+
変換関数の結果を基準に、2つ以上の配列の共通部分を返します
44

55
```typescript
6-
const result = intersectionBy(firstArr, secondArr, mapper);
6+
const result = intersectionBy(firstArr, secondArr, ...otherArr, mapper);
77
```
88

99
## 使用法
1010

11-
### `intersectionBy(firstArr, secondArr, mapper)`
11+
### `intersectionBy(firstArr, secondArr, ...otherArr?, mapper)`
1212

13-
2つの配列で特定の属性や変換された値を基準に共通の要素を見つけたい場合は `intersectionBy` を使用してください。各要素を変換関数で処理した結果を比較して交集合を求めます。オブジェクト配列で特定のプロパティで比較したり、複雑な変換ロジックが必要な場合に便利です。
13+
特定のプロパティや変換された値を基準に、2つ以上の配列から共通要素を見つけたい場合は`intersectionBy`を使用してください。各要素に変換関数を適用した結果を比較して共通部分を計算します。オブジェクト配列を特定のプロパティで比較する場合や、複雑な変換ロジックが必要な場合に便利です。
1414

1515
```typescript
1616
import { intersectionBy } from 'es-toolkit/array';
@@ -56,12 +56,26 @@ intersectionBy(numbers1, numbers2, num => Math.abs(num));
5656
// Returns: [-2, 3, -4]
5757
```
5858

59+
3つ以上の配列も比較できます。
60+
61+
```typescript
62+
import { intersectionBy } from 'es-toolkit/array';
63+
64+
// 3つの配列すべてに存在する要素を見つける
65+
const arr1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
66+
const arr2 = [{ id: 2 }, { id: 3 }];
67+
const arr3 = [{ id: 2 }, { id: 4 }];
68+
intersectionBy(arr1, arr2, arr3, item => item.id);
69+
// Returns: [{ id: 2 }, { id: 3 }]
70+
```
71+
5972
#### パラメータ
6073

6174
- `firstArr` (`readonly T[]`): 比較する最初の配列です。
6275
- `secondArr` (`readonly U[]`): 比較する2番目の配列です。
76+
- `...otherArr` (`readonly U[]`, オプション): 比較する追加の配列。
6377
- `mapper` (`(item: T | U) => unknown`): 各要素を変換して比較基準を作成する関数です。
6478

6579
#### 戻り値
6680

67-
(`T[]`): 変換関数の結果を基準に、両方の配列に共通して含まれる要素からなる新しい配列を返します。結果は最初の配列の要素で構成されます。
81+
(`T[]`): 変換された値を基準に、すべての配列に存在する最初の配列の要素を含む新しい配列を返します。結果は最初の配列の要素で構成されます。

docs/ko/reference/array/intersectionBy.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# intersectionBy
22

3-
변환 함수의 결과를 기준으로 두 배열의 교집합을 구한 새 배열을 반환해요.
3+
변환 함수의 결과를 기준으로 두 개 이상의 배열의 교집합을 구한 새 배열을 반환해요.
44

55
```typescript
6-
const result = intersectionBy(firstArr, secondArr, mapper);
6+
const result = intersectionBy(firstArr, secondArr, ...otherArr, mapper);
77
```
88

99
## 사용법
1010

11-
### `intersectionBy(firstArr, secondArr, mapper)`
11+
### `intersectionBy(firstArr, secondArr, ...otherArr?, mapper)`
1212

13-
두 배열에서 특정 속성이나 변환된 값을 기준으로 공통 요소를 찾고 싶을 때 `intersectionBy`를 사용하세요. 각 요소를 변환 함수로 처리한 결과를 비교해서 교집합을 구해요. 객체 배열에서 특정 속성으로 비교하거나 복잡한 변환 로직이 필요할 때 유용해요.
13+
개 이상의 배열에서 특정 속성이나 변환된 값을 기준으로 공통 요소를 찾고 싶을 때 `intersectionBy`를 사용하세요. 각 요소를 변환 함수로 처리한 결과를 비교해서 교집합을 구해요. 객체 배열에서 특정 속성으로 비교하거나 복잡한 변환 로직이 필요할 때 유용해요.
1414

1515
```typescript
1616
import { intersectionBy } from 'es-toolkit/array';
@@ -56,12 +56,26 @@ intersectionBy(numbers1, numbers2, num => Math.abs(num));
5656
// Returns: [-2, 3, -4]
5757
```
5858

59+
세 개 이상의 배열도 비교할 수 있어요.
60+
61+
```typescript
62+
import { intersectionBy } from 'es-toolkit/array';
63+
64+
// 세 배열 모두에 공통으로 존재하는 요소를 찾아요.
65+
const arr1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
66+
const arr2 = [{ id: 2 }, { id: 3 }];
67+
const arr3 = [{ id: 2 }, { id: 4 }];
68+
intersectionBy(arr1, arr2, arr3, item => item.id);
69+
// Returns: [{ id: 2 }, { id: 3 }]
70+
```
71+
5972
#### 파라미터
6073

6174
- `firstArr` (`readonly T[]`): 비교할 첫 번째 배열이에요.
6275
- `secondArr` (`readonly U[]`): 비교할 두 번째 배열이에요.
76+
- `...otherArr` (`readonly U[]`, 선택): 추가로 비교할 배열이에요
6377
- `mapper` (`(item: T | U) => unknown`): 각 요소를 변환해서 비교 기준을 만드는 함수예요.
6478

6579
#### 반환 값
6680

67-
(`T[]`): 변환 함수의 결과를 기준으로 배열에 공통으로 포함된 요소들로 이루어진 새 배열을 반환해요. 결과는 첫 번째 배열의 요소들로 구성돼요.
81+
(`T[]`): 변환 함수의 결과를 기준으로 모든 배열에 공통으로 포함된 요소들로 이루어진 새 배열을 반환해요. 결과는 첫 번째 배열의 요소들로 구성돼요.

docs/reference/array/intersectionBy.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# intersectionBy
22

3-
Returns a new array containing the intersection of two arrays based on the result of a transformation function.
3+
Returns the intersection of two or more arrays based on a mapping function.
44

55
```typescript
6-
const result = intersectionBy(firstArr, secondArr, mapper);
6+
const result = intersectionBy(firstArr, secondArr, ...otherArr, mapper);
77
```
88

99
## Usage
1010

11-
### `intersectionBy(firstArr, secondArr, mapper)`
11+
### `intersectionBy(firstArr, secondArr, ...otherArr?, mapper)`
1212

13-
Use `intersectionBy` when you want to find common elements in two arrays based on a specific attribute or transformed value. It compares the results of processing each element with a transformation function to find the intersection. This is useful when comparing by a specific property in object arrays or when complex transformation logic is needed.
13+
Use `intersectionBy` when you want to find common elements across two or more arrays based on a specific property or transformed value. It compares the results of applying a transformation function to each element to compute the intersection. This is useful when comparing object arrays by a specific property or when complex transformation logic is needed.
1414

1515
```typescript
1616
import { intersectionBy } from 'es-toolkit/array';
@@ -56,12 +56,26 @@ intersectionBy(numbers1, numbers2, num => Math.abs(num));
5656
// Returns: [-2, 3, -4]
5757
```
5858

59+
You can also compare three or more arrays.
60+
61+
```typescript
62+
import { intersectionBy } from 'es-toolkit/array';
63+
64+
// Find elements that exist in all three arrays
65+
const arr1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
66+
const arr2 = [{ id: 2 }, { id: 3 }];
67+
const arr3 = [{ id: 2 }, { id: 4 }];
68+
intersectionBy(arr1, arr2, arr3, item => item.id);
69+
// Returns: [{ id: 2 }, { id: 3 }]
70+
```
71+
5972
#### Parameters
6073

6174
- `firstArr` (`readonly T[]`): The first array to compare.
6275
- `secondArr` (`readonly U[]`): The second array to compare.
76+
- `...otherArr` (`readonly U[]`, optional): Additional arrays to compare.
6377
- `mapper` (`(item: T | U) => unknown`): A function that transforms each element to create comparison criteria.
6478

6579
#### Returns
6680

67-
(`T[]`): Returns a new array containing elements commonly included in both arrays based on the result of the transformation function. The result consists of elements from the first array.
81+
(`T[]`): Returns a new array containing elements from the first array that are present in all other arrays based on the transformed values. The result consists of elements from the first array.

docs/zh_hans/reference/array/intersectionBy.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# intersectionBy
22

3-
根据转换函数的结果为标准求两个数组的交集,返回一个新数组
3+
根据映射函数返回两个或多个数组的交集
44

55
```typescript
6-
const result = intersectionBy(firstArr, secondArr, mapper);
6+
const result = intersectionBy(firstArr, secondArr, ...otherArr, mapper);
77
```
88

99
## 用法
1010

11-
### `intersectionBy(firstArr, secondArr, mapper)`
11+
### `intersectionBy(firstArr, secondArr, ...otherArr?, mapper)`
1212

13-
当您想根据特定属性或转换后的值查找两个数组的共同元素时,请使用 `intersectionBy`它比较用转换函数处理每个元素后的结果来求交集。在对象数组中按特定属性比较或需要复杂转换逻辑时很有用
13+
当您想要根据特定属性或转换后的值在两个或多个数组中查找公共元素时,请使用 `intersectionBy`它通过比较对每个元素应用转换函数的结果来计算交集。这在按特定属性比较对象数组或需要复杂转换逻辑时非常有用
1414

1515
```typescript
1616
import { intersectionBy } from 'es-toolkit/array';
@@ -56,12 +56,26 @@ intersectionBy(numbers1, numbers2, num => Math.abs(num));
5656
// Returns: [-2, 3, -4]
5757
```
5858

59+
您也可以比较三个或更多数组。
60+
61+
```typescript
62+
import { intersectionBy } from 'es-toolkit/array';
63+
64+
// 查找在所有三个数组中都存在的元素
65+
const arr1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
66+
const arr2 = [{ id: 2 }, { id: 3 }];
67+
const arr3 = [{ id: 2 }, { id: 4 }];
68+
intersectionBy(arr1, arr2, arr3, item => item.id);
69+
// Returns: [{ id: 2 }, { id: 3 }]
70+
```
71+
5972
#### 参数
6073

6174
- `firstArr` (`readonly T[]`): 要比较的第一个数组。
6275
- `secondArr` (`readonly U[]`): 要比较的第二个数组。
76+
- `...otherArr` (`readonly U[]`, 可选): 要比较的其他数组。
6377
- `mapper` (`(item: T | U) => unknown`): 转换每个元素以创建比较标准的函数。
6478

6579
#### 返回值
6680

67-
(`T[]`): 返回根据转换函数的结果为标准,由两个数组共同包含的元素组成的新数组。结果由第一个数组的元素组成。
81+
(`T[]`): 返回一个新数组,包含第一个数组中根据转换后的值在所有其他数组中都存在的元素。结果由第一个数组的元素组成。

0 commit comments

Comments
 (0)