mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-24 11:45:26 +03:00
a82eb933ae
* feat(without): Add `without` function * feat(without): Add `without` function test code * feat(without): Add `without` function docs * feat(without): Add `without` function bench * Update docs/ko/reference/array/without.md * Apply suggestions from code review * Update src/array/without.ts * Update src/array/without.spec.ts --------- Co-authored-by: Sojin Park <raon0211@gmail.com>
43 lines
993 B
Markdown
43 lines
993 B
Markdown
# without
|
|
|
|
Creates an array that excludes all specified values.
|
|
|
|
It correctly excludes `NaN`, as it compares values using [SameValueZero](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-samevaluezero).
|
|
|
|
## Signature
|
|
|
|
```typescript
|
|
function without<T>(array: T[], ...values: T[]): T[];
|
|
```
|
|
|
|
### Parameters
|
|
|
|
- `array` (`T[]`): The array to exclude values.
|
|
- `values` (`...T[]`): The values to exclude.
|
|
|
|
### Returns
|
|
|
|
(`T[]`) A new array without the specified values.
|
|
|
|
## Examples
|
|
|
|
```typescript
|
|
import { without } from 'es-toolkit/array';
|
|
|
|
// Removes the specified values from the array
|
|
without([1, 2, 3, 4, 5], 2, 4);
|
|
// Returns: [1, 3, 5]
|
|
|
|
// Removes specified string values from the array
|
|
without(['a', 'b', 'c', 'a'], 'a');
|
|
// Returns: ['b', 'c']
|
|
|
|
// Handles cases where none of the specified values are in the array
|
|
without([1, 2, 3], 4, 5);
|
|
// Returns: [1, 2, 3]
|
|
|
|
// Handles cases with different types of values
|
|
without([1, '2', 3, '4'], 2, '4');
|
|
// Returns: [1, '2', 3]
|
|
```
|