1 | ;
|
2 | var toInteger = require('../internals/to-integer');
|
3 | var requireObjectCoercible = require('../internals/require-object-coercible');
|
4 |
|
5 | // `String.prototype.repeat` method implementation
|
6 | // https://tc39.github.io/ecma262/#sec-string.prototype.repeat
|
7 | module.exports = ''.repeat || function repeat(count) {
|
8 | var str = String(requireObjectCoercible(this));
|
9 | var result = '';
|
10 | var n = toInteger(count);
|
11 | if (n < 0 || n == Infinity) throw RangeError('Wrong number of repetitions');
|
12 | for (;n > 0; (n >>>= 1) && (str += str)) if (n & 1) result += str;
|
13 | return result;
|
14 | };
|