Advertisement
Hiteshw11

Dart function that takes a map of products and their stock quantities, and returns a list of product

Nov 21st, 2024
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.50 KB | Source Code | 0 0
  1. /* Write a Dart function that takes a map of products and their stock quantities, and returns a list of products that are out of stock.*/
  2.  
  3. void main() {
  4.   Map<String, int> stock = {'apple': 10, 'banana': 0, 'orange': 8, 'grape': 0};
  5.   print(checkStock(stock));
  6. }
  7.  
  8. List<String> checkStock(Map<String, int> stock) {
  9.   List<String> emptyStockList = [];
  10.  
  11.   for (MapEntry<String, int> e in stock.entries) {
  12.     if (e.value == 0) {
  13.       emptyStockList.add(e.key);
  14.     }
  15.   }
  16.   return emptyStockList;
  17. }
  18.  
Tags: dart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement