Skip to content

Instantly share code, notes, and snippets.

@xgqfrms
Created June 2, 2020 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xgqfrms/438dc75421d9d45b394fca73381b9cb7 to your computer and use it in GitHub Desktop.
Save xgqfrms/438dc75421d9d45b394fca73381b9cb7 to your computer and use it in GitHub Desktop.
js repeatify

ES6 version

repeatify

String.prototype.repeatify = function (times = 1) {
  console.log(this)
  // String {"abx"}
  return [...``.padStart(times, ` `)].map((item, i) => item = this).join(``);
};

`abx`.repeatify(3);
// "abxabxabx"
@xgqfrms
Copy link
Author

xgqfrms commented Jun 2, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment