From f06cfb655b3c5224ef7502de556feeb9b1300f3f Mon Sep 17 00:00:00 2001
From: Toufic Batache <taffou2a@gmail.com>
Date: Wed, 30 Oct 2024 17:10:17 +0100
Subject: [PATCH] Replace sendTestCasesSimulation() map with for loop

---
 src/lib/shared.svelte.ts | 56 +++++++++++++++++-----------------------
 1 file changed, 23 insertions(+), 33 deletions(-)

diff --git a/src/lib/shared.svelte.ts b/src/lib/shared.svelte.ts
index e21dbec9a..4ece5a4f5 100644
--- a/src/lib/shared.svelte.ts
+++ b/src/lib/shared.svelte.ts
@@ -751,39 +751,29 @@ async function sendTestCasesSimulation(
         // Split evaluation.value vector for each situation.
         {
           let testCasesPopulationIndex = 0
-          valuesByCalculationNameByVariableNameArray =
-            valuesByCalculationNameByVariableNameArray.map(
-              (
-                valuesByCalculationNameByVariableName,
-                situationIndex,
-              ): ValuesByCalculationNameByVariableName => {
-                const situation = shared.testCases[situationIndex]
-                const entitySituation =
-                  situation[entity.key_plural as string] ?? {}
-                let values = []
-                for (
-                  let index = testCasesPopulationIndex, vectorIndex = 0;
-                  vectorIndex < shared.vectorLength;
-                  index += testCasesPopulationCount, vectorIndex++
-                ) {
-                  for (const situationPersonIndex of Object.keys(
-                    entitySituation,
-                  ).keys()) {
-                    values.push(roundedValue[index + situationPersonIndex])
-                  }
-                }
-                testCasesPopulationIndex += Object.keys(entitySituation).length
-                const valuesByCalculationName =
-                  valuesByCalculationNameByVariableName[variableName] ?? {}
-                return {
-                  ...valuesByCalculationNameByVariableName,
-                  [variableName]: {
-                    ...valuesByCalculationName,
-                    [calculationName]: values,
-                  },
-                }
-              },
-            )
+          for (const [
+            situationIndex,
+            valuesByCalculationNameByVariableName,
+          ] of valuesByCalculationNameByVariableNameArray.entries()) {
+            const situation = shared.testCases[situationIndex]
+            const entitySituation = situation[entity.key_plural as string] ?? {}
+            const values: VariableValues = []
+            for (
+              let index = testCasesPopulationIndex, vectorIndex = 0;
+              vectorIndex < shared.vectorLength;
+              index += testCasesPopulationCount, vectorIndex++
+            ) {
+              for (const situationPersonIndex of Object.keys(
+                entitySituation,
+              ).keys()) {
+                values.push(roundedValue[index + situationPersonIndex])
+              }
+            }
+            testCasesPopulationIndex += Object.keys(entitySituation).length
+            ;(valuesByCalculationNameByVariableName[variableName] ??= {})[
+              calculationName
+            ] = values
+          }
         }
       } else {
         // Variable has been computed for a single test case.
-- 
GitLab