From ca79396e29285057a5ff8e8634b8f08cb6ccf625 Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Mon, 30 Jan 2023 14:17:56 -0800 Subject: [PATCH] doc: create getRandomPrompt function --- src/utils/index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/utils/index.js diff --git a/src/utils/index.js b/src/utils/index.js new file mode 100644 index 0000000..6450ccd --- /dev/null +++ b/src/utils/index.js @@ -0,0 +1,10 @@ +import { surpriseMePrompts } from "../constants"; + +export function getRandomPrompt(prompt) { + const randomIndex = Math.floor(Math.random() * surpriseMePrompts.length); + const randomPrompt = surpriseMePrompts[randomIndex]; + + if (randomPrompt === prompt) return getRandomPrompt(prompt); + + return randomPrompt; +}