Created
February 25, 2024 23:39
-
-
Save Shuvo8693/1eae8ee662f3de0815f139b827b0cd23 to your computer and use it in GitHub Desktop.
added the List Items by Loop or Iteration
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
add List of sum in a sigle value by this way ------------------------------- | |
void main() { | |
List<double> itemPrice= [15.99, 18.75, 21.40, 53.09]; | |
double sum=0; | |
double totalPrice=0; | |
var numbers= itemPrice.map((value)=> value).reduce((previous,present)=>previous+present); // we can use also fold() function | |
// for (double item in itemPrice) { | |
// sum+=item; | |
// totalPrice= sum * 1.05; // eta 5% vat soho | |
// } | |
print(numbers); // output 109.23 | |
} | |
----------------------------------------------------------------fold()------------------------------- | |
void main() { | |
List<double> itemPrice= [15.99, 18.75, 21.40, 53.09]; | |
double addedPrice=itemPrice.fold(0,(previous,current)=>previous+current); | |
double totalPrice= addedPrice * 1.05; | |
print(totalPrice); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment