Created
December 13, 2019 21:08
-
-
Save BNSby/0f1bd8d9646a4ed9429631980f607e14 to your computer and use it in GitHub Desktop.
Изучаем Dart 2019 / ДЗ по анонимным функциям / Задача 2
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
void main() { | |
List<int> data1 = [1, -10, 9, -1]; | |
List<int> data2 = [-1, -2, -3]; | |
List<int> data3 = []; | |
List<int> data4 = [1, 2]; | |
print(sumInt(data1)); | |
print(sumInt(data2)); | |
print(sumInt(data3)); | |
print(sumInt(data4)); | |
} | |
int sumInt(List<int> array) { | |
int sum = 0; | |
int cntOddArray = array.where((val) => val < 0).toList().length; | |
if (array.isEmpty || cntOddArray == array.length) { | |
return 0; | |
} else { | |
array.forEach((val) => val > 0 ? sum += val : sum); | |
} | |
return sum; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment