我正在尝试编写一个函数,只会将名字和姓氏的第一个字母大写......有关如何处理此问题的任何想法?
const namesHardest = ['emIly sMith', 'angeliNA Jolie', 'braD piTt'];
function capitalizeNames(peopleArray) {
return peopleArray.toString().toLowerCase().split('').map(function(word) {
return (word.charAt(0).toUpperCase() + word.slice(1));
}).join(' ').split();
}
// set the resulting array to this variabble
const capitalizedNames = capitalizeNames(namesHardest);
capitalizedNames;
Run Code Online (Sandbox Code Playgroud)