Created
May 10, 2020 17:15
-
-
Save ericwindmill/9f5065991b2194a12fc03fbf7c0fc0e3 to your computer and use it in GitHub Desktop.
fbe_dart_iterables_filter_where_takewhile
This file contains 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
This will require using `where` and `skipWhile` together |
This file contains 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> getOddNumsOver10(List<int> nums) { | |
// implement the logic to take any list of integers and return | |
// a new list that contains only the numbers in the list over 10 and that are odd. | |
// | |
// for example: List<int> sortedNums = [2, 5, 7, 10, 12, 19, 92, 106] | |
// would be transformed into [19] | |
} |
This file contains 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> getOddNumsOver10(List<int> nums) { | |
return nums.skipWhile((int n) => n < 11).where((int i) => i % 2 != 0).toList(); | |
} |
This file contains 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> sortedNums = [2, 5, 7, 10, 12, 19, 92, 106]; | |
void main() { | |
final oddNumsOver10 = getOddNumsOver10(sortedNums); | |
if (oddNumsOver10.contains(2) || | |
oddNumsOver10.contains(5) || | |
oddNumsOver10.contains(7) || | |
oddNumsOver10.contains(10)) { | |
_result(false, ['the function getOddNumsOver10 should not contain any numbers less than 11']); | |
} | |
if (oddNumsOver10.any((int i) => i % 2 == 0)) { | |
_result(false, ['the function getOddsOver10 should not contain any even numbers']); | |
} | |
_result(true, ['All tests passed.', 'yeet']); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment