|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
351 bytes
|
| Rev | Line | |
|---|
| [a762898] | 1 | import { toInteger } from './toInteger.mjs';
|
|---|
| 2 |
|
|---|
| 3 | function times(n, getValue) {
|
|---|
| 4 | n = toInteger(n);
|
|---|
| 5 | if (n < 1 || !Number.isSafeInteger(n)) {
|
|---|
| 6 | return [];
|
|---|
| 7 | }
|
|---|
| 8 | const result = new Array(n);
|
|---|
| 9 | for (let i = 0; i < n; i++) {
|
|---|
| 10 | result[i] = typeof getValue === 'function' ? getValue(i) : i;
|
|---|
| 11 | }
|
|---|
| 12 | return result;
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | export { times };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.