mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-28 03:34:26 +03:00
cf65b2c601
* chore: add prettierrc * chore: apply format with prettier config * chore: eslint error fix
32 lines
785 B
Markdown
32 lines
785 B
Markdown
# intersection
|
|
|
|
Returns the intersection of two arrays.
|
|
|
|
This function takes two arrays and returns a new array containing the elements that are
|
|
present in both arrays. It effectively filters out any elements from the first array that
|
|
are not found in the second array.
|
|
|
|
## Signature
|
|
|
|
```typescript
|
|
function intersection<T>(firstArr: T[], secondArr: T[]): T[];
|
|
```
|
|
|
|
### Parameters
|
|
|
|
- `firstArr` (`T[]`): The first array to compare.
|
|
- `secondArr` (`T[]`): The second array to compare.
|
|
|
|
### Returns
|
|
|
|
(`T[]`) A new array containing the elements that are present in both arrays.
|
|
|
|
## Examples
|
|
|
|
```typescript
|
|
const array1 = [1, 2, 3, 4, 5];
|
|
const array2 = [3, 4, 5, 6, 7];
|
|
const result = intersection(array1, array2);
|
|
// result will be [3, 4, 5] since these elements are in both arrays.
|
|
```
|