Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Custom dart function that accepts map as argument

Creating a custom function that accepts a map as an arugment and print the values of the map as a list. Expected output: [98, 95, 77, 89, 74, 99, 97]`

void main() {
  Map studentMarks = {
    'James': 98,
    'Peter': 95,
    'Alson': 77,
    'Deng': 89,
    'Diing': 74,
    'Madunt': 99,
    'Kwaje': 97
  };
  List marks = getScores(studentMarks);
  print(marks);
}

dynamic getScoresList(Map map) {
  map.entries.map((ele) => print(ele.value));
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You may try this:

void main() {
  Map studentMarks = {
    'James': 98,
    'Peter': 95,
    'Alson': 77,
    'Deng': 89,
    'Diing': 74,
    'Madunt': 99,
    'Kwaje': 97
  };
  List marks = getScoresList(studentMarks);
  print(marks);
}

List getScoresList(Map map) {
  return map.values.toList();
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading