diff --git a/src/oj/learn/components/ExerciseFill.vue b/src/oj/learn/components/ExerciseFill.vue index 34aba3f..9979ec3 100644 --- a/src/oj/learn/components/ExerciseFill.vue +++ b/src/oj/learn/components/ExerciseFill.vue @@ -1,11 +1,7 @@ - - diff --git a/src/oj/learn/composables/useShuffle.ts b/src/oj/learn/composables/useShuffle.ts new file mode 100644 index 0000000..9b77a45 --- /dev/null +++ b/src/oj/learn/composables/useShuffle.ts @@ -0,0 +1,9 @@ +// Fisher–Yates 洗牌,返回新数组,不修改原数组 +export function shuffle(arr: T[]): T[] { + const a = [...arr] + for (let i = a.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)) + ;[a[i], a[j]] = [a[j], a[i]] + } + return a +}