Skip to content

Instantly share code, notes, and snippets.

@dawnerd
Created September 16, 2014 02:38
Show Gist options
  • Save dawnerd/b177b934bd178c01a28e to your computer and use it in GitHub Desktop.
Save dawnerd/b177b934bd178c01a28e to your computer and use it in GitHub Desktop.
Makes text a "lot" better
var sign = "The best hotdogs in town.";
String.prototype.emphasize = function(options) {
options = options || {
minWordLength: 3
};
var wordRegex = new RegExp('(\\w{' + options.minWordLength + ',})', 'g');
var words = this.match(wordRegex);
if(!words) {
return this;
}
var selected = words[Math.floor(Math.random()*words.length)];
var newText = this.replace(selected, '"' + selected + '"');
return newText;
};
alert(sign.emphasize());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment