Last active
June 1, 2021 02:47
-
-
Save nickmeinhold/0b8c0d6cb87ccd5fa6415b35d4422fe3 to your computer and use it in GitHub Desktop.
Exercise: Practice using async and await
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| You can do it! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int addUpOverFives(List<int> input) { | |
| return input.where((i) => i > 5).fold<int>(0, (previous, current) => previous + current); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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