repeat.js 480 B

12345678910111213141516
  1. var makeString = require('./helper/makeString');
  2. var strRepeat = require('./helper/strRepeat');
  3. module.exports = function repeat(str, qty, separator) {
  4. str = makeString(str);
  5. qty = ~~qty;
  6. // using faster implementation if separator is not needed;
  7. if (separator == null) return strRepeat(str, qty);
  8. // this one is about 300x slower in Google Chrome
  9. /*eslint no-empty: 0*/
  10. for (var repeat = []; qty > 0; repeat[--qty] = str) {}
  11. return repeat.join(separator);
  12. };