From 4f518c48da563088576995d80136668d7675155a Mon Sep 17 00:00:00 2001 From: Anton Medvedev Date: Wed, 11 Dec 2024 23:52:34 +0100 Subject: [PATCH] Use paths length --- finder.js | 5 ++--- finder.ts | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/finder.js b/finder.js index 7e1e093..3e15f94 100644 --- a/finder.js +++ b/finder.js @@ -104,11 +104,10 @@ function bottomUpSearch(input, limit, fallback) { return path; } function findUniquePath(stack, fallback) { - const numberOfCombinations = stack.reduce((acc, level) => acc * level.length, 1); - if (numberOfCombinations > config.threshold) { + const paths = sort(combinations(stack)); + if (paths.length > config.threshold) { return fallback ? fallback() : null; } - const paths = sort(combinations(stack)); for (let candidate of paths) { if (unique(candidate)) { return candidate; diff --git a/finder.ts b/finder.ts index 398eeda..f896fb8 100644 --- a/finder.ts +++ b/finder.ts @@ -147,11 +147,10 @@ function findUniquePath( stack: Knot[][], fallback?: () => Path | null, ): Path | null { - const numberOfCombinations = stack.reduce((acc, level) => acc * level.length, 1) - if (numberOfCombinations > config.threshold) { + const paths = sort(combinations(stack)) + if (paths.length > config.threshold) { return fallback ? fallback() : null } - const paths = sort(combinations(stack)) for (let candidate of paths) { if (unique(candidate)) { return candidate