개발/Flutter
list에 있는 값들 모두 합치기
dev_caleb
2022. 8. 23. 23:32
728x90
[1,2,3,4,5,6] 이걸 다 합치면 몇이 될까?
for 를 쓰면 쉽게 되겠지
코드가 너무 길 것 같아서 줄일 수 있는 방법을 찾아보았다.
What is the cleanest way to get the sum of numbers in a collection/list in Dart?
I don't like using an indexed array for no reason other than I think it looks ugly. Is there a clean way to sum with an anonymous function? Is it possible to do it without using any outside variables?
stackoverflow.com
.sum 을 사용하려면
import 'package:collection/collection.dart';
를 해줘야함
728x90