Skip to content

Instantly share code, notes, and snippets.

@Headmast
Created October 2, 2020 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Headmast/57c6c3c9cc4b8504510164b8f132fe2c to your computer and use it in GitHub Desktop.
Save Headmast/57c6c3c9cc4b8504510164b8f132fe2c to your computer and use it in GitHub Desktop.
double average(List <double> darray) {
  double sum = 0;
  darray.forEach((value) 
                 {sum += value;}
                );
  return sum/darray.length;
  
}

void main() {
  List <double> darray = [2, 4, 2, 3];
  print ('Average: ${average(darray)}');
}
@artem-zaitsev
Copy link

В Dart не принято форматировать таким образом:

darray.forEach((value) 
                 {sum += value;}
                );

лучше

darray.forEach(
  (value) {
    sum += value;
  },
);

Более подробно про форматирование и стайл гайд можно посмотреть на https://dart.dev/guides/language/effective-dart

В остальном результат верный.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment