repeat method

String repeat([
  1. int n = 1
])

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;
}