Cycymomo
1/30/2014 - 8:14 AM

stringRepeat.js : Repeating strings efficiently

stringRepeat.js : Repeating strings efficiently

function stringRepeat(str, num) {
  var result = '';
  
  for (num |= 0; num > 0; num >>>= 1, str += str) {
    if (num & 1) {
      result += str;
    }
  }
  
  return result;
}