aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/client/utils/shuffle.ts
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-01-03 00:33:56 +0900
committernsfisis <nsfisis@gmail.com>2026-01-03 00:43:17 +0900
commit0d56a04d770c2df492ecf59c941e8d90578b0b60 (patch)
treeea62a0096ef03128be2c4f329eaa2d8592019d32 /src/client/utils/shuffle.ts
parent66bfde575d973fea9fb26139af421ab5b18c5bea (diff)
downloadkioku-0d56a04d770c2df492ecf59c941e8d90578b0b60.tar.gz
kioku-0d56a04d770c2df492ecf59c941e8d90578b0b60.tar.zst
kioku-0d56a04d770c2df492ecf59c941e8d90578b0b60.zip
feat(study): shuffle cards when starting study session
Cards are now randomized using Fisher-Yates algorithm to improve learning by preventing users from memorizing card order. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src/client/utils/shuffle.ts')
-rw-r--r--src/client/utils/shuffle.ts14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/client/utils/shuffle.ts b/src/client/utils/shuffle.ts
new file mode 100644
index 0000000..a2b8fec
--- /dev/null
+++ b/src/client/utils/shuffle.ts
@@ -0,0 +1,14 @@
+/**
+ * Fisher-Yates shuffle algorithm.
+ * Returns a new shuffled array (does not mutate the original).
+ */
+export function shuffle<T>(array: T[]): T[] {
+ const result = [...array];
+ for (let i = result.length - 1; i > 0; i--) {
+ const j = Math.floor(Math.random() * (i + 1));
+ const temp = result[i] as T;
+ result[i] = result[j] as T;
+ result[j] = temp;
+ }
+ return result;
+}