From 72bbaadfba8fae8031d99d442fc23e66cdfc7d3b Mon Sep 17 00:00:00 2001 From: Tyler-A Date: Mon, 6 Jul 2020 23:36:30 -0600 Subject: [PATCH] Extend the String prototype to allow easier title casing. --- js/prototypes.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 js/prototypes.js diff --git a/js/prototypes.js b/js/prototypes.js new file mode 100644 index 0000000..69f5556 --- /dev/null +++ b/js/prototypes.js @@ -0,0 +1,10 @@ +String.prototype.toTitleCase = function () { + let words = this.split(` `); + let new_words = []; + for (var word of words) { + new_words.push( + `${word[0].toUpperCase()}${word.slice(1).toLowerCase()}` + ); + }; + return new_words.join(` `); +} \ No newline at end of file