|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
713 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 | var floor = Math.floor;
|
|---|
| 8 |
|
|---|
| 9 | // `String.prototype.repeat` method implementation
|
|---|
| 10 | // https://tc39.es/ecma262/#sec-string.prototype.repeat
|
|---|
| 11 | module.exports = function repeat(count) {
|
|---|
| 12 | var str = toString(requireObjectCoercible(this));
|
|---|
| 13 | var result = '';
|
|---|
| 14 | var n = toIntegerOrInfinity(count);
|
|---|
| 15 | if (n < 0 || n === Infinity) throw new $RangeError('Wrong number of repetitions');
|
|---|
| 16 | for (;n > 0; (n = floor(n / 2)) && (str += str)) if (n % 2) result += str;
|
|---|
| 17 | return result;
|
|---|
| 18 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.