Created
August 21, 2020 04:26
-
-
Save shameemreza/ba932c29d30b9525b11afe999f72236b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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