_string-repeat.js 373 B

12345678910111213
  1. 'use strict';
  2. var toInteger = require('./_to-integer');
  3. var defined = require('./_defined');
  4. module.exports = function repeat(count) {
  5. var str = String(defined(this));
  6. var res = '';
  7. var n = toInteger(count);
  8. if (n < 0 || n == Infinity) throw RangeError("Count can't be negative");
  9. for (;n > 0; (n >>>= 1) && (str += str)) if (n & 1) res += str;
  10. return res;
  11. };