repeat method
returns repeated string
, n
number of times
'justkawal'.repeat(1); // justkawal
'123'.repeat(2); // 123123
'1'.repeat(5); // 11111
Implementation
String repeat([int n = 1]) {
if (n < 1) {
return '';
}
var result = '', string = this;
do {
if ((n % 2) > 0) {
result += string;
}
n = (n / 2).floor();
if (n > 0) {
string += string;
}
} while (n > 0);
return result;
}