From 215aa2577d9d2e0812a8c42c90bd1d7ba83d2028 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 22 Dec 2022 22:33:24 -0400 Subject: many homepage carousel shenanigans --- src/util/sugar.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/util') diff --git a/src/util/sugar.js b/src/util/sugar.js index e8fdf932..0813c1d4 100644 --- a/src/util/sugar.js +++ b/src/util/sugar.js @@ -40,6 +40,20 @@ export function empty(arrayOrNull) { } } +// Repeats all the items of an array a number of times. +export function repeat(times, array) { + if (typeof array === 'string') return repeat(times, [array]); + if (empty(array)) return []; + if (times === 0) return []; + if (times === 1) return array.slice(); + + const out = []; + for (let n = 1; n <= times; n++) { + out.push(...array); + } + return out; +} + // Sums the values in an array, optionally taking a function which maps each // item to a number (handy for accessing a certain property on an array of like // objects). This also coalesces null values to zero, so if the mapping function -- cgit 1.3.0-6-gf8a5