main
Last change
on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
681 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 | var toIntegerOrInfinity = require('../internals/to-integer-or-infinity');
|
---|
3 | var toString = require('../internals/to-string');
|
---|
4 | var requireObjectCoercible = require('../internals/require-object-coercible');
|
---|
5 |
|
---|
6 | var $RangeError = RangeError;
|
---|
7 |
|
---|
8 | // `String.prototype.repeat` method implementation
|
---|
9 | // https://tc39.es/ecma262/#sec-string.prototype.repeat
|
---|
10 | module.exports = function repeat(count) {
|
---|
11 | var str = toString(requireObjectCoercible(this));
|
---|
12 | var result = '';
|
---|
13 | var n = toIntegerOrInfinity(count);
|
---|
14 | if (n < 0 || n === Infinity) throw new $RangeError('Wrong number of repetitions');
|
---|
15 | for (;n > 0; (n >>>= 1) && (str += str)) if (n & 1) result += str;
|
---|
16 | return result;
|
---|
17 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.