Add cycle (repeat an array N times)
@ramongr is already working on this.
Since May 6, 2026.
Assessment
This issue has not been assessed yet.
Description
Updated 2026-05 to match the v2 standalone-function API and the issue template used by the rest of the helper backlog. Original 2021 description used the v1 `Array.prototype` style.
Operation
`cycle`
Category
transformations
Proposed signature
```ts
export function cycle(values: readonly T[], times: number): T[]
```
Why this isn't covered by native ES/TS
Expressible as `Array(n).fill(values).flat()`, but that allocates an intermediate array of arrays and is unergonomic. No dedicated native helper.
Empty / edge-case behaviour
- `times === 0` → `[]`.
- `times === 1` → shallow copy of `values`.
- `times < 0` or non-integer → throws `RangeError` (consistent with `inGroups` / `inGroupsOf`).
- Empty `values` → `[]` regardless of `times`.
- Returns a new array (no mutation).
Examples
```ts
cycle([1, 2, 3], 2); // [1, 2, 3, 1, 2, 3]
cycle([1, 2], 0); // []
cycle([], 5); // []
```
Acceptance criteria
- Implementation in `src/transformations/cycle.ts`
- Re-exported from `src/transformations/index.ts`
- Tests in `tests/transformations/cycle.test.ts` (incl. times=0, empty input, invalid times)
- Docs added in `docs/transformations.md`
- README API table updated
- Dominant language
- TypeScript
- Stars
- 2
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ramongr/op-array
-
additive v3-accepted
-
additive v3-accepted
-
additive v3-accepted
-
chore(v3.0): roadmap Openbreaking-change v3-accepted
All issues in ramongr/op-array
Similar issues
-
comp/dashboard P3 type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
NousResearch/hermes-agent#117722 ·
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·