From: Ardis Lu Date: Fri, 15 Mar 2024 03:13:15 +0000 (-0700) Subject: De-duplicate permutations output X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=86671367aae573f3f6fd31ea2ce08a8d8561bd22;p=seed-phrase-transposer De-duplicate permutations output Otherwise, a 4-word grid will have duplicate outputs --- diff --git a/main.ts b/main.ts index 2f77e63..824d803 100644 --- a/main.ts +++ b/main.ts @@ -45,7 +45,7 @@ export function getPermutations( horizontalTB[horizontalIndex] = word; } - return [verticalLR.join(" "), horizontalTB.join(" ")]; + return Array.from(new Set([verticalLR.join(" "), horizontalTB.join(" ")])); } /** diff --git a/main_test.ts b/main_test.ts index fc6d33c..370808f 100644 --- a/main_test.ts +++ b/main_test.ts @@ -67,6 +67,13 @@ User enters: getPermutations should return: [ "1 2 3 4 5 6 7 8 9 10 11 12", "1 10 8 6 4 2 11 9 7 5 3 12" ] */ +const test4WordGrids = [ + { + testName: "2-column vertical-lr incorrectly recorded as horizontal-tb", + words: "1 3 2 4".split(" "), + columns: 2, + }, +]; const test12WordGrids = [ { testName: "2-column vertical-lr incorrectly recorded as horizontal-tb", @@ -139,6 +146,13 @@ const test24WordGrids = [ columns: 12, }, ]; +Deno.test("getPermutations returns correct permutations of 4-word test grids", () => { + test4WordGrids.forEach((grid) => { + const permutations = getPermutations(grid.words, grid.columns); + assertArrayIncludes(permutations, ["1 2 3 4"]); + assertEquals(permutations.length, 1); // Should de-duplicate + }); +}); Deno.test("getPermutations returns correct permutations of 12-word test grids", () => { test12WordGrids.forEach((grid) => { const permutations = getPermutations(grid.words, grid.columns);