Advertisement
AnasB

Dart2

Jun 3rd, 2021
804
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int sum(List<int> intList, int index) {
  2.   if (index == 0) {
  3.     return intList[index];
  4.   } else {
  5.     return intList[index] + sum(intList, index - 1);
  6.   }
  7. }
  8.  
  9. void main() {
  10.   var test = [4, 2, 3, 4];
  11.   var result = sum(test, 3);
  12.   print(result);
  13. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement