« get me outta code hell

many homepage carousel shenanigans - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2022-12-22 22:33:24 -0400
committer(quasar) nebula <qznebula@protonmail.com>2022-12-22 22:33:24 -0400
commit215aa2577d9d2e0812a8c42c90bd1d7ba83d2028 (patch)
treebf7d2b36ec9f1fbb2dcea0fcfaf165d367b7fa92 /src/util
parente6f233025c0e511bb472bb75540d50381b58db48 (diff)
many homepage carousel shenanigans
Diffstat (limited to 'src/util')
-rw-r--r--src/util/sugar.js14
1 files changed, 14 insertions, 0 deletions
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