Last active
January 29, 2022 12:59
-
-
Save angelabauer/88fd2dd04c921892515bcd0567ef1636 to your computer and use it in GitHub Desktop.
for in loop challenge for Dart
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> winningNumbers = [12, 6, 34, 22, 41, 9]; | |
| void main() { | |
| List<int> ticket1 = [45, 2, 9, 18, 12, 33]; | |
| List<int> ticket2 = [41, 17, 26, 32, 7, 35]; | |
| checkNumbers(ticket1); | |
| } | |
| void checkNumbers(List<int> myNumbers) { | |
| //Write your code here. | |
| } |
athirdev
commented
Jan 24, 2022
void checkNumbers(List<int> myNumbers) {
int match = 0;
for (int i = 0; i < myNumbers.length; i++) {
match += winningNumbers.any((n) => n == myNumbers[i]) ? 1 : 0;
}
print('You have $match matching number.');
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment