Programming in Dart: Functions & Closures

Jun 21 2022 · Dart 2.16, Flutter, DartPad

Part 2: Learn Anonymous Functions & Closures

17. Challenge: Write a Generic Function

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 16. Learn Generic Functions Next episode: 18. Conclusion

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Now it’s time for the last and final challenge of this course. You just watched two episodes on generics. Now it’s time to put your knowledge to the test.

var scores = [
    [96, 46, 87],
    [87, 78, 80],
    [90, 86, 95],
];

var interests = [
    ['Video Games', 'Reading', 'Soccer'],
    ['Gymnastics', 'Step Dancing', 'Softball'],
    ['Horseback Riding', 'Hockey', 'Writing']
];
List<T>
List<T> flattenList
List<T> flattenList<T>
List<T> flattenList<T>(List<List<T>> list) {

}
var flatList = <T>[];
for (var item in list) {
    for (var subItem in item) {

    }
}
flatList.add(subItem);
return flatList;
// Takes in a list of lists and extracts all items into a single list
var flatScores = flattenList(scores);
var flatInterests = flattenList(interests);
print(flatScores);
print(flatInterests);