Created
September 16, 2014 02:38
-
-
Save dawnerd/b177b934bd178c01a28e to your computer and use it in GitHub Desktop.
Makes text a "lot" better
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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