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 () {
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
)
: [];
......
......@@ -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;
};
/**
......
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