Advertisement
Hiteshw11

returns a new map with only the tasks that are not completed.

Nov 21st, 2024
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.59 KB | Source Code | 0 0
  1. /*Write a Dart function that takes a map of tasks and their completion status (true for completed, false for not completed), and returns a new map with only the tasks that are not completed.*/
  2.  
  3.  
  4.  
  5. void main() {
  6.  Map<String,bool> tasks ={'Task A':true,'Task B':false,'Task C':true,'Task D':false};
  7.  
  8.  print(taskChecker(tasks));
  9.  
  10. }
  11.  
  12. Map<String,bool> taskChecker(tasks)
  13. {
  14.   Map<String,bool> incompleteTasks={};
  15.  
  16.   for(MapEntry<String,bool> e in tasks.entries)
  17.   {
  18.     if(e.value==false)
  19.     {
  20.       incompleteTasks[e.key]=e.value;
  21.     }
  22.   }
  23.   return incompleteTasks;
  24.  
  25.  
  26. }
  27.  
Tags: dart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement