Advertisement
Hiteshw11

Map Values Greater Than Threshold

Nov 22nd, 2024
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.56 KB | Source Code | 0 0
  1. /* Write a Dart function that takes a map and a threshold value, returning a new map containing only the entries with values greater than the threshold.*/
  2.  
  3. void main() {
  4.   Map<String, int> scores = {'Alice': 85, 'Bob': 92, 'Charlie': 78, 'Diana': 89};
  5.   int threshold = 80;
  6.   print(checker(scores, threshold));
  7. }
  8.  
  9. Map<String, int> checker(Map<String, int> scores, int threshold) {
  10.   Map<String, int> checking = {};
  11.   for (MapEntry<String, int> e in scores.entries) {
  12.     if (e.value > threshold) {
  13.       checking[e.key] = e.value;
  14.     }
  15.   }
  16.   return checking;
  17. }
Tags: dart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement