Skip to content

Instantly share code, notes, and snippets.

@SeeThruHead
Last active August 29, 2015 14:26
Show Gist options
  • Save SeeThruHead/9d7021d017c6aef302e5 to your computer and use it in GitHub Desktop.
Save SeeThruHead/9d7021d017c6aef302e5 to your computer and use it in GitHub Desktop.
String.prototype.repeatify = function(x) {
// Array.apply(null, {length: x}) creates an array of undefined values with length x
return Array.apply(null, {length: x}).map(() => this).join('');
};
// or a better but less fun solution
String.prototype.repeatify = function(x) {
return Array(x + 1).join(this);
};
console.log('hi'.repeatify(10));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment