Created
February 14, 2022 17:41
-
-
Save micedreams/3de3ee97ae87bcee130ad641711f91c0 to your computer and use it in GitHub Desktop.
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
void main() { | |
int resultsumOf; | |
resultsumOf = sumOf([9, 34, -23, 0, 4, 8,1]); | |
print("sumOf([9, 34, -23, 0, 4, 8,1]) =$resultsumOf"); | |
resultsumOf = sumOf([901, 492, -10223, 3791, 243, 2]); | |
print("sumOf([901, 492, -10223, 3791, 243, 2]) =$resultsumOf"); | |
} | |
int sumOf(List<int> integers) { | |
int result = 0; | |
for(var i=0; i<integers.length/2;i++){ | |
if(!(integers.length%2==0)&&i==0){ | |
result = result + integers[i]; | |
}else{ | |
result = result + integers[i]+ integers[integers.length-1-i]; | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment