Menu
Coddy logo textTech

Recap - Data Filtering

Part of the Logic & Flow section of Coddy's Dart journey — lesson 16 of 65.

challenge icon

Challenge

Easy

Create a program that manages a data analytics pipeline by filtering, transforming, and processing numerical datasets. Your program should:

  1. Read a string input representing the dataset name
  2. Read multiple integer inputs representing raw data values (the input will end when you receive -1)
  3. Read an integer input representing the minimum value threshold for filtering
  4. Use the where() method to filter values that are greater than the threshold
  5. Use the map() method to square each filtered value
  6. Use the toList() method to convert the final result into a list
  7. 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 processed

If 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 processed

If 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 processed

Your 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