From 9de7c53641af85d5185bb1f57d102dc3d53d6083 Mon Sep 17 00:00:00 2001 From: Mikhail Bodrov Date: Sun, 14 Jul 2024 22:03:30 +0300 Subject: [PATCH] Simplify array reduce with flatMap --- scripts/genFeatures.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/genFeatures.ts b/scripts/genFeatures.ts index d772e71..f40d714 100644 --- a/scripts/genFeatures.ts +++ b/scripts/genFeatures.ts @@ -108,7 +108,7 @@ const run = async () => { fs.mkdir(GEN_DIR, { recursive: true }); const allFeatures: FeatureType[] = files - .map((filePath) => + .flatMap((filePath) => readAsJSON(filePath).map((feature) => { return { weight: 0, @@ -117,9 +117,6 @@ const run = async () => { } as FeatureType; }), ) - .reduce((carry: FeatureType[], features: FeatureType[]) => { - return carry.concat(features); - }, []) .sort((a, b) => a.weight - b.weight); await Promise.all([