]> git.ardis.lu - seed-phrase-transposer/commitdiff
De-duplicate permutations output
authorArdis Lu <ardisglu@gmail.com>
Fri, 15 Mar 2024 03:13:15 +0000 (20:13 -0700)
committerArdis Lu <ardisglu@gmail.com>
Fri, 15 Mar 2024 03:13:15 +0000 (20:13 -0700)
Otherwise, a 4-word grid will have duplicate outputs

main.ts
main_test.ts

diff --git a/main.ts b/main.ts
index 2f77e632c0534a157770557d6a7fd88c396c84ed..824d803ecaa3abdba4b94223a179aeb9c987aa32 100644 (file)
--- 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(" ")]));
 }
 
 /**
index fc6d33c54995afd27519eae1db7dab442a2e1c8b..370808fc50c4668f8f6a005b2be6f9e7afcb4013 100644 (file)
@@ -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<string>(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);
This page took 0.036265 seconds and 4 git commands to generate.