Skip to content

Commit

Permalink
types(times): improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
haoziqaq committed Nov 14, 2024
1 parent 088d9bb commit 88080c0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions docs/number/times.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ times(5, (index) => `Item ${index}`)

### Arguments

| Arg | Type | Defaults |
| ----- | :--------------------: | -------: |
| `num` | `number` | |
| `fn` | `(index: number) => T` | |
| Arg | Type | Defaults |
| ----- | :----------------------: | -------: |
| `num` | `number` | |
| `fn` | `(index: number) => any` | |

### Return

| Type |
| :---: |
| `T[]` |
| Type |
| :-----: |
| `Array` |
14 changes: 7 additions & 7 deletions docs/zh/number/times.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ times(5, (index) => `Item ${index}`)

### 参数

| 参数 | 类型 | 默认值 |
| ----- | :--------------------: | -----: |
| `num` | `number` | |
| `fn` | `(index: number) => T` | |
| 参数 | 类型 | 默认值 |
| ----- | :----------------------: | -----: |
| `num` | `number` | |
| `fn` | `(index: number) => any` | |

### 返回值

| 类型 |
| :---: |
| `T[]` |
| 类型 |
| :-----: |
| `Array` |
2 changes: 1 addition & 1 deletion src/number/times.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function times<T>(num: number, fn: (index: number) => T) {
export function times<T>(num: number, fn: (index: number) => T): T[] {
return Array.from({ length: num }, (_, index) => fn(index))
}

0 comments on commit 88080c0

Please sign in to comment.