要求: 确保字符串的每个单词首字母都大写,其余部分小写. 像'the'和'of'这样的连接符同理. 结果: titleCase("I'm a little tea pot") 应该返回一个字符串 titleCase("I'm a little tea pot") 应该返回 "I'm A Little Tea Pot". titleCase("sHoRt AnD sToUt") 应该返回 "Short And Stou…
Title Case a Sentence(中单词首字母大写) 要求 确保字符串的每个单词首字母都大写,其余部分小写. 像'the'和'of'这样的连接符同理. 思路 将句子小写化后用.split(" ")将句子分隔成各单词组成的数组, 再用for循环将数组中每个单词用.split('')分隔成各个字母组成的数组,将数组中第一个元素大写,即首字母大写后用.join('')将字母合成单词 最后将各数组单词用.join(' ')合成句子 代码 function titleCase(str)…
地址:http://www.codewars.com/kata/5202ef17a402dd033c000009/train/python 题目: A string is considered to be in title case if each word in the string is either (a) capitalised (that is, only the first letter of the word is in upper case) or (b) considered…
freecodecamp 初级算法地址戳这里 Reverse a String 翻转字符串 function reverseString(str) { str=str.split("").reverse().join(""); return str; } reverseString("hello") Factorialize a Number 计算一个整数的阶乘 function factorialize(num) { if(num>1){…