diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3883851..7dc1c80 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,11 @@ name: CI on: + pull_request: + paths: + - 'functions/**' + branches: + - master push: paths: - 'functions/**' @@ -28,6 +33,7 @@ jobs: npm run test deploy: + if: github.event == 'push' needs: test runs-on: ubuntu-latest steps: @@ -48,4 +54,4 @@ jobs: with: args: deploy --only functions env: - FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }} \ No newline at end of file + FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }} diff --git a/functions/src/util/shuffle.ts b/functions/src/util/shuffle.ts index 7a9415f..b91d53e 100644 --- a/functions/src/util/shuffle.ts +++ b/functions/src/util/shuffle.ts @@ -26,20 +26,23 @@ export function cut(array: T[], cutVariance: number = 10): T[] { export function fisherYatesModifiedShuffleCutFive(array: T[]): T[] { if (array.length <= 1) return array; + //loop five times for (let i = 0; i < 5; i++) { - //run a Fisher-Yates Shuffle - for (let i = 0; i < array.length; i++) { - const randomChoiceIndex = getRandom(i, array.length - 1); - [array[i], array[randomChoiceIndex]] = [array[randomChoiceIndex], array[i]]; - } - //cut the deck - const cv = Math.min(array.length, cutVariance); - const cutPos = Math.floor(Math.random() * cv) + ((array.length - cv) / 2); - const bottom = array.slice(0, cutPos); - const top = array.slice(cutPos); - - } + + //run a Fisher-Yates Shuffle + for (let i = 0; i < array.length; i++) { + const randomChoiceIndex = getRandom(i, array.length - 1); + [array[i], array[randomChoiceIndex]] = [array[randomChoiceIndex], array[i]]; + } + //cut the deck + const cv = Math.min(array.length, 10); + const cutPos = Math.floor(Math.random() * cv) + ((array.length - cv) / 2); + const bottom = array.slice(0, cutPos); + const top = array.slice(cutPos); + array = top.concat(bottom); + } + //return the array return array; }