Exercise: Data Pipeline Aggregator
Problem statement
In data science pipelines, incoming datasets often contain corrupted or missing values. The objective is to build a high-performance utility that scans a dataset exactly once and ignores missing data. It must extract the minimum, maximum, and average values for further analysis.
Task requirements
Create a utility class inside a dedicated file to process the data.
Implement a method that accepts an array of nullable doubles.
Calculate the minimum, maximum, and average of the valid (non-null) data points in a single iteration.
Output these three metrics directly to the caller without allocating a dedicated return object.
Handle the edge case where the array is empty or contains only null values by returning
false(andtrueif processing succeeds).
Constraints
Use a
staticclass and astaticmethod, and place them in theDataSciencenamespace within their own file.Use
double?[]for the input array.Use the
outmodifier to return themin,max, andaveragevalues alongside the method's boolean return type.Use a single
foreachorforloop to achieve a single-pass calculation.
Good luck trying the exercise! If you’re unsure how to proceed, check the “Solution” tab above.
Get hints
Initialize the local tracking minimum to
double.MaxValueand the maximum todouble.MinValuebefore the loop.Use the
HasValueproperty or theis not nullpattern to filter out corrupted data points during the iteration.An
outparameter must be assigned a value before the method exits. Assign them0at the very beginning of the method to satisfy the compiler in case you need to returnfalseearly.
Exercise: Data Pipeline Aggregator
Problem statement
In data science pipelines, incoming datasets often contain corrupted or missing values. The objective is to build a high-performance utility that scans a dataset exactly once and ignores missing data. It must extract the minimum, maximum, and average values for further analysis.
Task requirements
Create a utility class inside a dedicated file to process the data.
Implement a method that accepts an array of nullable doubles.
Calculate the minimum, maximum, and average of the valid (non-null) data points in a single iteration.
Output these three metrics directly to the caller without allocating a dedicated return object.
Handle the edge case where the array is empty or contains only null values by returning
false(andtrueif processing succeeds).
Constraints
Use a
staticclass and astaticmethod, and place them in theDataSciencenamespace within their own file.Use
double?[]for the input array.Use the
outmodifier to return themin,max, andaveragevalues alongside the method's boolean return type.Use a single
foreachorforloop to achieve a single-pass calculation.
Good luck trying the exercise! If you’re unsure how to proceed, check the “Solution” tab above.
Get hints
Initialize the local tracking minimum to
double.MaxValueand the maximum todouble.MinValuebefore the loop.Use the
HasValueproperty or theis not nullpattern to filter out corrupted data points during the iteration.An
outparameter must be assigned a value before the method exits. Assign them0at the very beginning of the method to satisfy the compiler in case you need to returnfalseearly.