Files
discord.js/packages/util/src/functions/range.ts
Suneet Tipirneni b2ec865765 feat: add @discordjs/util (#8591)
* feat: add @discordjs/util

* fix: builders test

* refactor: make rest use lazy for ESM import

* chore: make requested changes

* Apply suggestions from code review

Co-authored-by: Parbez <imranbarbhuiya.fsd@gmail.com>
Co-authored-by: A. Román <kyradiscord@gmail.com>

* chore: make requested changes and add tests

* chore: regen lockfile

* test: add type tests

* chore: push missing files

* chore: make requested changes

* chore: update CI stuff

* chore: fix lockfile

* chore: make requested changes

Co-authored-by: Parbez <imranbarbhuiya.fsd@gmail.com>
Co-authored-by: A. Román <kyradiscord@gmail.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-10-02 18:00:31 +00:00

21 lines
540 B
TypeScript

/**
* Yields the numbers in the given range as an array
*
* @param start - The start of the range
* @param end - The end of the range (inclusive)
* @param step - The amount to increment between each number
* @example
* Basic range
* ```ts
* range(3, 5); // [3, 4, 5]
* ```
* @example
* Range with a step
* ```ts
* range(3, 10, 2); // [3, 5, 7, 9]
* ```
*/
export function range(start: number, end: number, step = 1): number[] {
return Array.from({ length: (end - start) / step + 1 }, (_, index) => start + index * step);
}