Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import 'package:meta/meta.dart';
int sum(List<int> list, [int initial = 0]) {
var total = initial;
list.forEach((v) => total += v);
return total;
}
String joinToString(List<String> list,
{@required String separator, String prefix = ", String
suffix = "}) =>
'$prefix${list.join(separator)}$suffix';
void main() {
assert(sum([1, 2, 3]) == 6);
assert(sum([1, 2, 3], 10) == 16);
assert(joinToString(['a', 'b', 'c'], separator: ',') ==
'a,b,c');
assert(
joinToString(['a', 'b', 'c'], separator: '-', prefix:
'*', suffix: '?') ==
'*a-b-c?');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.