Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save IAmAnubhavSaini/7996b7d189244f3cce28 to your computer and use it in GitHub Desktop.
Save IAmAnubhavSaini/7996b7d189244f3cce28 to your computer and use it in GitHub Desktop.
This is without Javascript Harmony.
function repeat(str, n){
if(n <= 0 || str.length === 0){
return '';
}
if(n === Infinity){
throw new RangeError("I cannot repeat a string Infinity times!");
}
n = Math.floor(+n);
var nstr = '';
for(var i = 0; i < n; i++){
nstr += str;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment