Recap - Data Filtering
Part of the Logic & Flow section of Coddy's Dart journey — lesson 16 of 65.
Challenge
EasyCreate a program that manages a data analytics pipeline by filtering, transforming, and processing numerical datasets. Your program should:
- Read a string input representing the dataset name
- Read multiple integer inputs representing raw data values (the input will end when you receive
-1) - Read an integer input representing the minimum value threshold for filtering
- Use the
where()method to filter values that are greater than the threshold - Use the
map()method to square each filtered value - Use the
toList()method to convert the final result into a list - Print the data processing results in the exact format shown below
For example, if the dataset name is "Sales Data", the raw values are 2, 5, 1, 8, 3, 6, and the threshold is 3, your program should output:
Dataset: Sales Data
Raw data: [2, 5, 1, 8, 3, 6]
Threshold: 3
Filtering values > 3
Filtered values: (5, 8, 6)
Squaring filtered values
Squared values: (25, 64, 36)
Final processed data: [25, 64, 36]
Processing complete: 3 values processedIf the dataset name is "Temperature Readings", the raw values are 1, 2, and the threshold is 5, your program should output:
Dataset: Temperature Readings
Raw data: [1, 2]
Threshold: 5
Filtering values > 5
Filtered values: ()
Squaring filtered values
Squared values: ()
Final processed data: []
Processing complete: 0 values processedIf the dataset name is "Performance Metrics", the raw values are 4, 7, 9, and the threshold is 2, your program should output:
Dataset: Performance Metrics
Raw data: [4, 7, 9]
Threshold: 2
Filtering values > 2
Filtered values: (4, 7, 9)
Squaring filtered values
Squared values: (16, 49, 81)
Final processed data: [16, 49, 81]
Processing complete: 3 values processedYour program must chain the operations in this exact sequence: first use where() to filter values greater than the threshold, then use map() to square each filtered value, and finally use toList() to convert the result into a list. The intermediate results should show the iterable format in parentheses, while the final list should be displayed in square brackets format.
Try it yourself
import 'dart:io';
void main() {
// Read dataset name
String? datasetName = stdin.readLineSync();
// Read raw data values until -1 is encountered
List<int> rawData = [];
while (true) {
int value = int.parse(stdin.readLineSync()!);
if (value == -1) break;
rawData.add(value);
}
// Read threshold value
int threshold = int.parse(stdin.readLineSync()!);
// Display initial information
print('Dataset: $datasetName');
print('Raw data: $rawData');
print('Threshold: $threshold');
print('Filtering values > $threshold');
// TODO: Write your code below
// Use where() to filter values greater than threshold
// Use map() to square each filtered value
// Use toList() to convert the result into a list
// Print the results in the required format
// Remember to show filtered values in parentheses format
// Show squared values in parentheses format
// Show final processed data in square brackets format
// Print processing complete message with count
}All lessons in Logic & Flow
1Advanced List Manipulation
List Properties: first & lastList State: isEmpty & isNotEmpReversing a ListAdding to a List: insertList Removal: removeWhereFinding in a List: indexOfSorting a ListShuffling a ListRecap - List Organizer4Advanced Map Manipulation
Iterating Over a MapChecking for Keys and ValuesMap Properties: keys & valuesConditional Add: putIfAbsentRemoving Entries from a MapNested MapsRecap - Inventory Update2Functional List Operations
Transforming with 'map'Filtering with 'where'Using '.toList()'Checking Conditions with 'any'Conditions with 'every'Finding with 'firstWhere'Recap - Data Filtering5Project: Shopping Cart Calc
Project SetupAdding Items to the Cart3Sets
What is a Set?Creating a SetAdding and Removing from SetsChecking for Elements in a SetConverting a List to a SetSet UnionSet IntersectionSet DifferenceRecap - Unique Guest List