Skip to content

Instantly share code, notes, and snippets.

@qetr1ck-op
Last active September 27, 2015 20:43
Show Gist options
  • Save qetr1ck-op/df77c34e3efec24039e6 to your computer and use it in GitHub Desktop.
Save qetr1ck-op/df77c34e3efec24039e6 to your computer and use it in GitHub Desktop.
/*
1. create method in string prototype
2. it should return multiple repeated string by n times
consle.log( "foo".repeat(3) ); // 'foofoofoo'
*/
String.prototype.repeat = function(times) { //or use built-in ES6 repeat()
return new Array(times + 1).join(this);
};
consle.log( "foo".repeat(3) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment