rep

var rep = function(/*String*/str, /*Integer*/num){
 // summary:
 //  Efficiently replicate a string `n` times.
 // str:
 //  the string to replicate
 // num:
 //  number of times to replicate the string
 
 if(num <= 0 || !str){ return ""; }
 
 var buf = [];
 for(;;){
  if(num & 1){
   buf.push(str);
  }
  if(!(num >>= 1)){ break; }
  str += str;
 }
 return buf.join(""); // String
};

你可能感兴趣的:(r)