From 0bc96c6a798f240bd4f515aef69a2a80332fbc9e Mon Sep 17 00:00:00 2001 From: Pithon Kabiro <pithon.kabiro@hft-stuttgart.de> Date: Fri, 22 Oct 2021 18:27:45 +0200 Subject: [PATCH] Edit function: delete temperature diff options - Create a copy of the array passed in as an argument, which will be modified in place - Replace 'forEach' method with 'filter' method for brevity --- public/js/appChart.js | 22 ++++++------------ public/js/src_modules/dropDownListHelpers.mjs | 23 ++++++++----------- 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/public/js/appChart.js b/public/js/appChart.js index 5fffe09..d7acae3 100644 --- a/public/js/appChart.js +++ b/public/js/appChart.js @@ -179,32 +179,24 @@ const drawChartUsingSelectedOptions = async function () { selectedBuildingsDataPointsSamplingRateAbbrevNestedArr ); - // Create copies of the arrays of building(s) + data point(s) + sampling rate - const selectedBuildingsDataPointsSamplingRateAbbrevRawObsCopyArr = [ - ...selectedBuildingsDataPointsSamplingRateAbbrevNestedArr, - ]; - - const selectedBuildingsDataPointsSamplingRateAbbrevTempDiffCopyArr = [ - ...selectedBuildingsDataPointsSamplingRateAbbrevNestedArr, - ]; - - // Check if we have raw observations + // Check whether we have dT (temperature difference), if so, delete these options, + // then compute abbreviations for raw observations const selectedBuildingsDataPointsSamplingRateAbbrevRawObsArr = checkIfSelectedOptionsContainTemperatureDifference( - selectedBuildingsDataPointsSamplingRateAbbrevRawObsCopyArr + selectedBuildingsDataPointsSamplingRateAbbrevNestedArr ) ? deleteTemperatureDifferenceOptions( - selectedBuildingsDataPointsSamplingRateAbbrevRawObsCopyArr + selectedBuildingsDataPointsSamplingRateAbbrevNestedArr ) - : selectedBuildingsDataPointsSamplingRateAbbrevRawObsCopyArr; + : selectedBuildingsDataPointsSamplingRateAbbrevNestedArr; // Check if we have dT (temperature difference) const selectedBuildingsDataPointsSamplingRateAbbrevTempDiffArr = checkIfSelectedOptionsContainTemperatureDifference( - selectedBuildingsDataPointsSamplingRateAbbrevTempDiffCopyArr + selectedBuildingsDataPointsSamplingRateAbbrevNestedArr ) ? extractTemperatureDifferenceOptions( - selectedBuildingsDataPointsSamplingRateAbbrevTempDiffCopyArr + selectedBuildingsDataPointsSamplingRateAbbrevNestedArr ) : []; diff --git a/public/js/src_modules/dropDownListHelpers.mjs b/public/js/src_modules/dropDownListHelpers.mjs index 3f2a8ff..50ffbb8 100644 --- a/public/js/src_modules/dropDownListHelpers.mjs +++ b/public/js/src_modules/dropDownListHelpers.mjs @@ -180,31 +180,28 @@ const getIndexesOfTemperatureDifferenceOptions = function ( const deleteTemperatureDifferenceOptions = function ( buildingDataPointSamplingRateAbbrevArr ) { + // Create a copy of the input array, will be modified in place + const buildingDataPointSamplingRateAbbrevCopyArr = [ + ...buildingDataPointSamplingRateAbbrevArr, + ]; + // Calculate the index(es) that we wish to delete const foundIndexesArr = getIndexesOfTemperatureDifferenceOptions( - buildingDataPointSamplingRateAbbrevArr + buildingDataPointSamplingRateAbbrevCopyArr ); // Delete the index(es) of `dT`, modifies the array in place // Note: The resulting array is sparse foundIndexesArr.forEach( - (foundIndex) => delete buildingDataPointSamplingRateAbbrevArr[foundIndex] + (foundIndex) => + delete buildingDataPointSamplingRateAbbrevCopyArr[foundIndex] ); - // Array to store our final result - const buildingDataPointFinalArr = []; - // Remove the empty sub array(s) that makes entire array sparse // Note: `empty` does not mean `undefined` or `null` - buildingDataPointSamplingRateAbbrevArr.forEach( - (bldgDataPntSmplingRateAbbrvArr) => { - if (typeof bldgDataPntSmplingRateAbbrvArr === "object") { - buildingDataPointFinalArr.push(bldgDataPntSmplingRateAbbrvArr); - } - } + return buildingDataPointSamplingRateAbbrevCopyArr.filter( + (bldgDataPntSamplingRate) => typeof bldgDataPntSamplingRate === "object" ); - - return buildingDataPointFinalArr; }; /** -- GitLab