_string-repeat.js 366 B

123456789101112
  1. 'use strict';
  2. var toInteger = require('./_to-integer')
  3. , defined = require('./_defined');
  4. module.exports = function repeat(count){
  5. var str = String(defined(this))
  6. , res = ''
  7. , 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. };