How to sum set elements in Dart

1 Answer

0 votes
int sum(int result, int element ) {
    return result + element ;
}

void main() {
    Set<int> st = {1, 2, 3, 5, 6, 8, 4, 16, 18, 33};
    
    var sum_st = st.reduce(sum);
    
    print(sum_st);
    
    print(st);
}
  
  
  
  
  
/*
run:
  
96
{1, 2, 3, 5, 6, 8, 4, 16, 18, 33}
  
*/

 



answered Oct 10, 2022 by avibootz

Related questions

1 answer 238 views
1 answer 240 views
1 answer 191 views
191 views asked Oct 10, 2022 by avibootz
2 answers 296 views
1 answer 264 views
2 answers 288 views
288 views asked Oct 10, 2022 by avibootz
1 answer 273 views
...