|
Last change
on this file since ba17441 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
485 bytes
|
| Line | |
|---|
| 1 | function rangeRight(start, end, step = 1) {
|
|---|
| 2 | if (end == null) {
|
|---|
| 3 | end = start;
|
|---|
| 4 | start = 0;
|
|---|
| 5 | }
|
|---|
| 6 | if (!Number.isInteger(step) || step === 0) {
|
|---|
| 7 | throw new Error(`The step value must be a non-zero integer.`);
|
|---|
| 8 | }
|
|---|
| 9 | const length = Math.max(Math.ceil((end - start) / step), 0);
|
|---|
| 10 | const result = new Array(length);
|
|---|
| 11 | for (let i = 0; i < length; i++) {
|
|---|
| 12 | result[i] = start + (length - i - 1) * step;
|
|---|
| 13 | }
|
|---|
| 14 | return result;
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | export { rangeRight };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.