mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-24 03:32:58 +03:00
fix(min, max): Do not return undefined
in non-empty arrays (#270)
* fix: improve min&max type * Apply suggestions from code review --------- Co-authored-by: Sojin Park <raon0211@gmail.com>
This commit is contained in:
parent
999a4daf87
commit
d117481dc4
@ -11,7 +11,9 @@
|
||||
## 인터페이스
|
||||
|
||||
```typescript
|
||||
function max<T>(items: T[]): T;
|
||||
function max<T>(items: [T, ...T[]]): T;
|
||||
function max(): undefined;
|
||||
function max<T>(items?: T[]): T | undefined;
|
||||
```
|
||||
|
||||
### 파라미터
|
||||
|
@ -11,7 +11,9 @@
|
||||
## 인터페이스
|
||||
|
||||
```typescript
|
||||
function min<T>(items: T[]): T;
|
||||
function min<T>(items: [T, ...T[]]): T;
|
||||
function min(): undefined;
|
||||
function min<T>(items?: T[]): T | undefined;
|
||||
```
|
||||
|
||||
### 파라미터
|
||||
|
@ -11,7 +11,9 @@ If the list is empty, returns `undefined`.
|
||||
## Signature
|
||||
|
||||
```typescript
|
||||
function max<T>(items: T[]): T;
|
||||
function max<T>(items: [T, ...T[]]): T;
|
||||
function max(): undefined;
|
||||
function max<T>(items?: T[]): T | undefined;
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
@ -11,7 +11,9 @@ If the list is empty, returns `undefined`.
|
||||
## Signature
|
||||
|
||||
```typescript
|
||||
function min<T>(items: T[]): T;
|
||||
function min<T>(items: [T, ...T[]]): T;
|
||||
function min(): undefined;
|
||||
function min<T>(items?: T[]): T | undefined;
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
@ -11,7 +11,9 @@
|
||||
## 签名
|
||||
|
||||
```typescript
|
||||
function max<T>(items: T[]): T;
|
||||
function max<T>(items: [T, ...T[]]): T;
|
||||
function max(): undefined;
|
||||
function max<T>(items?: T[]): T | undefined;
|
||||
```
|
||||
|
||||
### 参数
|
||||
|
@ -11,7 +11,9 @@
|
||||
## 签名
|
||||
|
||||
```typescript
|
||||
function min<T>(items: T[]): T;
|
||||
function min<T>(items: [T, ...T[]]): T;
|
||||
function min(): undefined;
|
||||
function min<T>(items?: T[]): T | undefined;
|
||||
```
|
||||
|
||||
### 参数
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* @template T - The type of elements in the array.
|
||||
* @param {T[]} items The array of elements to search.
|
||||
* @returns {T} The element with the maximum value.
|
||||
* @returns {T | undefined} The element with the maximum value.
|
||||
* @example
|
||||
* // Returns 9
|
||||
* max([3, 1, 4, 1, 5, 9])
|
||||
@ -12,7 +12,10 @@
|
||||
* // Returns 8
|
||||
* max([0, -3, 2, 8, 7])
|
||||
*/
|
||||
export function max<T>(items: readonly T[] = []): T {
|
||||
export function max<T>(items: readonly [T, ...T[]]): T;
|
||||
export function max(): undefined;
|
||||
export function max<T>(items?: readonly T[]): T | undefined;
|
||||
export function max<T>(items: readonly T[] = []): T | undefined {
|
||||
let maxElement = items[0];
|
||||
let max = undefined;
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* @template T - The type of elements in the array.
|
||||
* @param {T[]} items The array of elements to search.
|
||||
* @returns {T} The element with the minimum value.
|
||||
* @returns {T | undefined} The element with the minimum value.
|
||||
* @example
|
||||
* // Returns 1
|
||||
* min([3, 1, 4, 1, 5, 9])
|
||||
@ -12,6 +12,9 @@
|
||||
* // Returns -3
|
||||
* min([0, -3, 2, 8, 7])
|
||||
*/
|
||||
export function min<T>(items: readonly [T, ...T[]]): T;
|
||||
export function min(): undefined;
|
||||
export function min<T>(items?: readonly T[]): T | undefined;
|
||||
export function min<T>(items: readonly T[] = []): T {
|
||||
let minElement = items[0];
|
||||
let min = undefined;
|
||||
|
Loading…
Reference in New Issue
Block a user