Skip to content

Instantly share code, notes, and snippets.

@iampawan
Created April 17, 2020 07:16
Show Gist options
  • Save iampawan/76a5c019175c0819961949c4351feab9 to your computer and use it in GitHub Desktop.
Save iampawan/76a5c019175c0819961949c4351feab9 to your computer and use it in GitHub Desktop.
void main() {
final myNumbers = [11,25,87,127,10,55,67,38,52,119,131,99];
// Rookie Way
num sum = 0;
for (int i = 0; i < myNumbers.length; i++) {
sum += myNumbers[i];
}
print(sum); // prints 821
//Handy Way
print(myNumbers.reduce((curr,next)=>curr+next)); // prints 821
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment