From e254ad385d33739d3e6b4a04d79325e2bca840b8 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 19 Jun 2024 19:50:38 -0300 Subject: sugar: pick --- src/util/sugar.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/util/sugar.js b/src/util/sugar.js index 3fa3fb46..3c5c2e9a 100644 --- a/src/util/sugar.js +++ b/src/util/sugar.js @@ -60,6 +60,11 @@ export function repeat(times, array) { return out; } +// Gets a random item from an array. +export function pick(array) { + return array[Math.floor(Math.random() * array.length)]; +} + // Gets the item at an index relative to another index. export function atOffset(array, index, offset, { wrap = false, -- cgit 1.3.0-6-gf8a5