From 82aed19f85d428321ab4719419fe73a7a097bab6 Mon Sep 17 00:00:00 2001 From: Fabian Stamm Date: Wed, 11 Sep 2019 18:36:31 +0200 Subject: [PATCH] Randomize order of options --- src/rand.ts | 9 +++++++++ src/views/questions/SelectMultiple.svelte | 4 +++- src/views/questions/SelectOne.svelte | 5 +++-- 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 src/rand.ts diff --git a/src/rand.ts b/src/rand.ts new file mode 100644 index 0000000..451c63f --- /dev/null +++ b/src/rand.ts @@ -0,0 +1,9 @@ +export default function randomize(input: T[]): T[] { + let res: T[] = []; + input = [...input]; + while (input.length > 0) { + let randomIndex = Math.floor(Math.random() * input.length); + res.push(...input.splice(randomIndex, 1)); + } + return res; +} \ No newline at end of file diff --git a/src/views/questions/SelectMultiple.svelte b/src/views/questions/SelectMultiple.svelte index 381a64e..993ecfd 100644 --- a/src/views/questions/SelectMultiple.svelte +++ b/src/views/questions/SelectMultiple.svelte @@ -1,10 +1,12 @@