Quantcast
Channel: freeCodeCamp Challenge Guide: Title Case a Sentence
Viewing all articles
Browse latest Browse all 50

freeCodeCamp Challenge Guide: Title Case a Sentence

$
0
0

@mazzaroth808 wrote:

                                MY SOLUTION
titleCase(Str) {
    
     var oldArr = str.toLowerCase().split(' ');
     var newArr = [];
     
     for (var i in oldArr) {
         var newWord = oldArr[i][0].toUpperCase() + oldArr[i].slice(1);
         newArr.push(newWord);
        }
     return newArr.join(' ');
}

there’s no need for:

for (var i = 0; i < oldArr.length; i++) {
}

because:

for (var i in oldArr) {
}

will loop through the entire length of oldArr without the need of a loop counter.

Read full topic


Viewing all articles
Browse latest Browse all 50

Trending Articles


Re:Mutton Pies (lleechef)


Tagalog Quotes About Crush – Tagalog Love Quotes


OFW quotes : Pinoy Tagalog Quotes


Pamatay na Banat and Mga Patama Love Quotes


5 Tagalog Relationship Rules


INUMAN QUOTES


Vimeo 10.7.0 by Vimeo.com, Inc.


Vimeo 10.7.1 by Vimeo.com, Inc.