Created
October 25, 2025 09:55
-
-
Save raidenz/ed457f0da50474fed71d845d2cec9795 to your computer and use it in GitHub Desktop.
re loop dummy image
This file contains hidden or 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
| // use for fake data | |
| const images = [1, 2, 3, 4] | |
| const articles = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
| const paired = articles.map((article, i) => ({ | |
| article, | |
| image: images[i % images.length], | |
| })) | |
| // --- | |
| export function cycleArray<T>(source: T[], count: number): T[] { | |
| return Array.from({ length: count }, (_, i) => source[i % source.length]) | |
| } | |
| const cycledImages = cycleArray(images, articles.length) | |
| // --- | |
| export function cycleArray<T>(arr: T[], index: number): T { | |
| return arr[index % arr.length] | |
| } | |
| const paired = articles.map((article, i) => ({ | |
| article, | |
| image: cycleArray(images, i), | |
| })) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment