From 1926c2d20e54881897c30b7f013a2172fc2a508a Mon Sep 17 00:00:00 2001 From: Luis Felipe Jimenez Ferreira Date: Sat, 11 Mar 2017 13:23:56 -0500 Subject: [PATCH] Create capitalizeEachWord Prototype function for string objects that will capitalize each word in the string you put it with For example: let sentence = "i am the best here"; sentence.capitalizeEachWord(); Will return each word of the sentence capitalized except for words that are less than 3 in length --- capitalizeEachWord | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 capitalizeEachWord diff --git a/capitalizeEachWord b/capitalizeEachWord new file mode 100644 index 0000000..7aa1b77 --- /dev/null +++ b/capitalizeEachWord @@ -0,0 +1,15 @@ +String.prototype.capitalizeEachWord = function() { + let words = this.split(" "); + for (var x = 0; x < words.length; x++) { + let word = words[x]; + + if (word.length <= 3) { + continue; + } else { + sentence = sentence.replace(word[0], word[0].toUpperCase()); + } + + } + return sentence; + +}