Skip to content

Instantly share code, notes, and snippets.

@gabrielseco
Created September 23, 2016 19:17
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 gabrielseco/fe50fb23fe26e2a333fae876fb21e703 to your computer and use it in GitHub Desktop.
Save gabrielseco/fe50fb23fe26e2a333fae876fb21e703 to your computer and use it in GitHub Desktop.
Random capitalization
/*
INSPIRED BY JOHN GREEN'S BOOK PAPER TOWNS
DEMO: http://codepen.io/GGarciaSeco/pen/mAWAyk
*/
String.prototype.capitalize = function(){
return Math.round(Math.random()) === 1 ? this.charAt(0).toUpperCase() + this.slice(1) + " ": this;
}
function randomCapitalization(phrase){
return phrase.split(" ")
.map(word => word.capitalize())
.join(" ");
}
const test = `3 whole catfish, wrapped separately
veet (it's for shaving your legs only you don't need a razor)
it's with all the girly cosmetic stuff
vaseline
six-pack, mountain dew
one dozen tulips
one bottle of water
tissues
one can of blue spray paint
`;
document.body.innerText = randomCapitalization(test);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment