Commit 0bc96c6a authored by Pithon Kabiro's avatar Pithon Kabiro
Browse files

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
parent 1a3ed99d
...@@ -179,32 +179,24 @@ const drawChartUsingSelectedOptions = async function () { ...@@ -179,32 +179,24 @@ const drawChartUsingSelectedOptions = async function () {
selectedBuildingsDataPointsSamplingRateAbbrevNestedArr selectedBuildingsDataPointsSamplingRateAbbrevNestedArr
); );
// Create copies of the arrays of building(s) + data point(s) + sampling rate // Check whether we have dT (temperature difference), if so, delete these options,
const selectedBuildingsDataPointsSamplingRateAbbrevRawObsCopyArr = [ // then compute abbreviations for raw observations
...selectedBuildingsDataPointsSamplingRateAbbrevNestedArr,
];
const selectedBuildingsDataPointsSamplingRateAbbrevTempDiffCopyArr = [
...selectedBuildingsDataPointsSamplingRateAbbrevNestedArr,
];
// Check if we have raw observations
const selectedBuildingsDataPointsSamplingRateAbbrevRawObsArr = const selectedBuildingsDataPointsSamplingRateAbbrevRawObsArr =
checkIfSelectedOptionsContainTemperatureDifference( checkIfSelectedOptionsContainTemperatureDifference(
selectedBuildingsDataPointsSamplingRateAbbrevRawObsCopyArr selectedBuildingsDataPointsSamplingRateAbbrevNestedArr
) )
? deleteTemperatureDifferenceOptions( ? deleteTemperatureDifferenceOptions(
selectedBuildingsDataPointsSamplingRateAbbrevRawObsCopyArr selectedBuildingsDataPointsSamplingRateAbbrevNestedArr
) )
: selectedBuildingsDataPointsSamplingRateAbbrevRawObsCopyArr; : selectedBuildingsDataPointsSamplingRateAbbrevNestedArr;
// Check if we have dT (temperature difference) // Check if we have dT (temperature difference)
const selectedBuildingsDataPointsSamplingRateAbbrevTempDiffArr = const selectedBuildingsDataPointsSamplingRateAbbrevTempDiffArr =
checkIfSelectedOptionsContainTemperatureDifference( checkIfSelectedOptionsContainTemperatureDifference(
selectedBuildingsDataPointsSamplingRateAbbrevTempDiffCopyArr selectedBuildingsDataPointsSamplingRateAbbrevNestedArr
) )
? extractTemperatureDifferenceOptions( ? extractTemperatureDifferenceOptions(
selectedBuildingsDataPointsSamplingRateAbbrevTempDiffCopyArr selectedBuildingsDataPointsSamplingRateAbbrevNestedArr
) )
: []; : [];
......
...@@ -180,31 +180,28 @@ const getIndexesOfTemperatureDifferenceOptions = function ( ...@@ -180,31 +180,28 @@ const getIndexesOfTemperatureDifferenceOptions = function (
const deleteTemperatureDifferenceOptions = function ( const deleteTemperatureDifferenceOptions = function (
buildingDataPointSamplingRateAbbrevArr 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 // Calculate the index(es) that we wish to delete
const foundIndexesArr = getIndexesOfTemperatureDifferenceOptions( const foundIndexesArr = getIndexesOfTemperatureDifferenceOptions(
buildingDataPointSamplingRateAbbrevArr buildingDataPointSamplingRateAbbrevCopyArr
); );
// Delete the index(es) of `dT`, modifies the array in place // Delete the index(es) of `dT`, modifies the array in place
// Note: The resulting array is sparse // Note: The resulting array is sparse
foundIndexesArr.forEach( 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 // Remove the empty sub array(s) that makes entire array sparse
// Note: `empty` does not mean `undefined` or `null` // Note: `empty` does not mean `undefined` or `null`
buildingDataPointSamplingRateAbbrevArr.forEach( return buildingDataPointSamplingRateAbbrevCopyArr.filter(
(bldgDataPntSmplingRateAbbrvArr) => { (bldgDataPntSamplingRate) => typeof bldgDataPntSamplingRate === "object"
if (typeof bldgDataPntSmplingRateAbbrvArr === "object") {
buildingDataPointFinalArr.push(bldgDataPntSmplingRateAbbrvArr);
}
}
); );
return buildingDataPointFinalArr;
}; };
/** /**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment