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 172 views
1 answer 147 views
1 answer 145 views
1 answer 109 views
109 views asked Oct 10, 2022 by avibootz
2 answers 160 views
1 answer 161 views
2 answers 162 views
162 views asked Oct 10, 2022 by avibootz
...