-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
37 additions
and
0 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,27 @@ | ||
/** | ||
* 创建一个包含从 start 到 end,但不包含 end 本身范围数字的数组。 | ||
* | ||
* @param start 开始数字 | ||
* @param [end] 结束数字 | ||
* @param [step] 步进值 | ||
* @returns 开始到结束范围内数字组成的数组 | ||
*/ | ||
export default function range(start: number, end?: number, step?: number): number[] { | ||
if (arguments.length === 1) { | ||
if (start > 0) { | ||
end = start | ||
start = 0 | ||
} else { | ||
end = 0 | ||
} | ||
step = 1 | ||
} else { | ||
step = step == null ? 1 : step | ||
} | ||
const result: number[] = [] | ||
while (start < end) { | ||
result.push(start) | ||
start += step | ||
} | ||
return result | ||
} |
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