📜  javascript 大写单词 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:26.750000             🧑  作者: Mango

代码示例6
function capitalize(paragraph) {
  const paragraphCleaned = paragraph.replace(/\s{2,}/, " ")
  const paragraphSplitted = paragraphCleaned.split(" ")
  const capitalized = paragraphSplitted.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
  return capitalized.join(" ")
}