Skip to content

Instantly share code, notes, and snippets.

@nickmeinhold
Last active June 1, 2021 02:47
Show Gist options
  • Select an option

  • Save nickmeinhold/0b8c0d6cb87ccd5fa6415b35d4422fe3 to your computer and use it in GitHub Desktop.

Select an option

Save nickmeinhold/0b8c0d6cb87ccd5fa6415b35d4422fe3 to your computer and use it in GitHub Desktop.
Exercise: Practice using async and await
You can do it!
// Complete the addUpOverFives() function so that it sums all elements of a given list that are greater than 5.
int addUpOverFives(List<int> input) {
return
}
int addUpOverFives(List<int> input) {
return input.where((i) => i > 5).fold<int>(0, (previous, current) => previous + current);
}
List<int> a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89];
main() async {
try {
var result = addUpOverFives(a);
if (result == 220) {
_result(true);
} else {
_result(false, ['Not quite... try again!']);
}
} on UnimplementedError {
_result(false, [
'Test failed! Did you remove the addUpOverFives function?',
]);
} catch (e) {
_result(false, ['Tried to run solution, but received an exception: $e']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment