-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/zipObject
- Loading branch information
Showing
35 changed files
with
566 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { bench, describe } from 'vitest'; | ||
import { compact as compactToolkit } from 'es-toolkit'; | ||
import { compact as compactLodash } from 'lodash'; | ||
|
||
describe('compact', () => { | ||
bench('es-toolkit', () => { | ||
compactToolkit([0, 1, false, 2, '', 3, null, undefined, 4, NaN, 5]); | ||
}); | ||
|
||
bench('lodash', () => { | ||
compactLodash([0, 1, false, 2, '', 3, null, undefined, 4, NaN, 5]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { bench, describe } from 'vitest'; | ||
import { mean as meanToolkit } from 'es-toolkit'; | ||
import { mean as meanLodash } from 'lodash'; | ||
|
||
describe('mean', () => { | ||
bench('es-toolkit/mean', () => { | ||
meanToolkit([1, 2, 3]); | ||
}); | ||
|
||
bench('lodash/mean', () => { | ||
meanLodash([1, 2, 3]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { bench, describe } from 'vitest'; | ||
import { range as rangeToolkit } from 'es-toolkit'; | ||
import { range as rangeLodash } from 'lodash'; | ||
|
||
describe('range', () => { | ||
bench('es-toolkit/range', () => { | ||
rangeToolkit(0, 100, 1); | ||
}); | ||
|
||
bench('lodash/range', () => { | ||
rangeLodash(0, 100, 1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# compact | ||
|
||
거짓으로 평가될 수 있는 값인 `false`, `null`, `0`, `''`, `undefined`, `NaN`을 제거한 새로운 배열을 반환해요. | ||
|
||
## 인터페이스 | ||
|
||
```typescript | ||
function compact<T>(arr: T[]): Array<Exclude<T, false | null | 0 | '' | undefined>>; | ||
``` | ||
|
||
### 파라미터 | ||
|
||
- `arr` (`T[]`): 거짓으로 평가될 수 있는 값을 제거할 배열 | ||
|
||
### 반환 값 | ||
|
||
(`Array<Exclude<T, false | null | 0 | '' | undefined>>`): 거짓으로 평가될 수 있는 값을 모두 제거한 새로운 배열 | ||
|
||
## 예시 | ||
|
||
```typescript | ||
compact([0, 1, false, 2, '', 3, null, undefined, 4, NaN, 5]); | ||
// 반환 값: [1, 2, 3, 4, 5] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# maxBy | ||
|
||
함수가 반환하는 값을 기준으로, 배열에서 최댓값을 가지는 요소를 반환해요. | ||
|
||
배열이 비어 있다면, `undefined`를 반환해요. | ||
|
||
## 인터페이스 | ||
|
||
```typescript | ||
function maxBy<T>(items: T[], getValue: (element: T) => number): T; | ||
``` | ||
|
||
### 파라미터 | ||
|
||
- `items` (`T[]`): 최댓값을 가지는 요소를 찾을 배열. | ||
- `getValue` (`(element: T) => number`): 요소에 해당되는 숫자를 계산하는 함수. | ||
|
||
### 반환 값 | ||
|
||
(`T`): `getValue` 함수를 기준으로, 배열에서 최댓값을 가지는 요소. 배열이 비어 있다면 `undefined`를 반환해요. | ||
|
||
### Example | ||
|
||
```typescript | ||
maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 } | ||
maxBy([], x => x.a); // Returns: undefined | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# minBy | ||
|
||
함수가 반환하는 값을 기준으로, 배열에서 최솟값을 가지는 요소를 반환해요. | ||
|
||
배열이 비어 있다면, `undefined`를 반환해요. | ||
|
||
## 인터페이스 | ||
|
||
```typescript | ||
function minBy<T>(items: T[], getValue: (element: T) => number): T; | ||
``` | ||
|
||
### 파라미터 | ||
|
||
- `items` (`T[]`): 최솟값을 가지는 요소를 찾을 배열. | ||
- `getValue` (`(element: T) => number`): 요소에 해당되는 숫자를 계산하는 함수. | ||
|
||
### 반환 값 | ||
|
||
(`T`): `getValue` 함수를 기준으로, 배열에서 최솟값을 가지는 요소. 배열이 비어 있다면 `undefined`를 반환해요. | ||
|
||
### Example | ||
|
||
```typescript | ||
minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 } | ||
minBy([], x => x.a); // Returns: undefined | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# mean | ||
|
||
숫자 배열의 평균을 계산하는 함수에요. 빈 배열에 대해서는 `NaN`을 반환해요. | ||
|
||
## 인터페이스 | ||
|
||
```typescript | ||
function mean(nums: number[]): number; | ||
``` | ||
|
||
### 파라미터 | ||
|
||
- `nums` (`number[]`): 평균을 계산할 숫자 배열이에요. | ||
|
||
### 반환 값 | ||
|
||
(`number`): 배열에 있는 모든 숫자의 평균을 반환해요. | ||
|
||
## 예시 | ||
|
||
```typescript | ||
const numbers = [1, 2, 3, 4, 5]; | ||
const result = mean(numbers); | ||
// result는 3이 되어요. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# range | ||
|
||
`start`에서 시작해서 `end` 전에 끝나는 숫자의 배열을 반환해요. 연속한 숫자는 `step` 만큼 차이가 나요. | ||
|
||
`step`이 기본값은 1이고, 0일 수 없어요. | ||
|
||
## 인터페이스 | ||
|
||
```typescript | ||
function range(end: number): number[]; | ||
function range(start: number, end: number): number[]; | ||
function range(start: number, end: number, step: number): number[]; | ||
``` | ||
|
||
### 파라미터 | ||
|
||
- `start` (`number`): 시작할 숫자. 배열은 이 숫자를 포함해요. | ||
- `end` (`number`): 끝날 숫자. 배열은 이 숫자를 포함하지 않아요. | ||
- `step` (`number`): 배열에서 연속한 숫자의 차이. 기본값은 `1`이에요. | ||
|
||
### 반환 값 | ||
|
||
- (`number[]`): `start`에서 시작해서 `end` 전에 끝나는, 연속한 숫자가 `step` 만큼 차이나는 배열. | ||
|
||
## 예시 | ||
|
||
```typescript | ||
// Returns [0, 1, 2, 3] | ||
range(4); | ||
|
||
// Returns [0, 5, 10, 15] | ||
range(0, 20, 5); | ||
|
||
// Returns [] | ||
range(0, -4, -1); | ||
|
||
// Throws an error: The step value must be a non-zero integer. | ||
range(1, 4, 0); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# compact | ||
|
||
Removes falsey values (`false`, `null`, `0`, `''`, `undefined`, `NaN`) from an array. | ||
|
||
## Signature | ||
|
||
```typescript | ||
function compact<T>(arr: T[]): Array<Exclude<T, false | null | 0 | '' | undefined>>; | ||
``` | ||
|
||
### Parameters | ||
|
||
- `arr` (`T[]`): The input array to remove falsey values. | ||
|
||
### Returns | ||
|
||
(`Array<Exclude<T, false | null | 0 | '' | undefined>>`) A new array with all falsey values removed. | ||
|
||
## Examples | ||
|
||
```typescript | ||
compact([0, 1, false, 2, '', 3, null, undefined, 4, NaN, 5]); | ||
// Returns: [1, 2, 3, 4, 5] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# maxBy | ||
|
||
Finds the element in an array that has the maximum value when applying the `getValue` function to each element. | ||
|
||
If the list is empty, returns `undefined`. | ||
|
||
## Signature | ||
|
||
```typescript | ||
function maxBy<T>(items: T[], getValue: (item: T) => number): T; | ||
``` | ||
|
||
### Parameters | ||
|
||
- `items` (`T[]`): The array of elements to search. | ||
- `getValue` (`(item: T) => number`): A function that selects a numeric value from each element. | ||
|
||
### Returns | ||
|
||
The element with the maximum value as determined by the `getValue` function. | ||
|
||
### Example | ||
|
||
```typescript | ||
maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 } | ||
maxBy([], x => x.a); // Returns: undefined | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# minBy | ||
|
||
Finds the element in an array that has the minimum value when applying the `getValue` function to each element. | ||
|
||
If the list is empty, returns `undefined`. | ||
|
||
## Signature | ||
|
||
```typescript | ||
function minBy<T>(items: T[], getValue: (item: T) => number): T; | ||
``` | ||
|
||
### Parameters | ||
|
||
- `items` (`T[]`): The array of elements to search. | ||
- `getValue` (`(item: T) => number`): A function that selects a numeric value from each element. | ||
|
||
### Returns | ||
|
||
The element with the minimum value as determined by the `getValue` function. | ||
|
||
### Example | ||
|
||
```typescript | ||
minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 } | ||
minBy([], x => x.a); // Returns: undefined | ||
``` |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.