Title Case a Sentence-freecodecamp algorithm topic

Source: Internet
Author: User

Title case a sentence (uppercase in the first letter of the word)
  1. Requirements
    • Make sure that the first letter of each word in the string is capitalized, and the remainder is lowercase.
    • Connectors like ' the ' and ' of ' are the same.
  2. Ideas
    • Use. Split ("") to separate sentences into an array of words.
    • Use the For loop to separate each word in the array with. Split (") into an array of letters, with the first element in the array capitalized, i.e. the first letter capitalized. Join (") to compose the word
    • Finally, each array word is combined with a. Join (') to compose the sentence
  3. Code
    1. 1 functiontitlecase (str) {2   //please write down your code here.3   varTemp1 = Str.tolowercase (). Split ("");4    for(varI =0;i<temp1.length;i++){5Temp1[i] = temp1[i].split (' ');6temp1[i][0]= temp1[i][0].touppercase ();7Temp1[i] = temp1[i].join (' ');8   }9str = temp1.join (' ');Ten   returnstr; One } A  -Titlecase ("I ' m a Little tea pot");
  4. RELATED LINKS
    • Https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/split

Title Case a Sentence-freecodecamp algorithm topic

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.