DEV Community 👩‍💻👨‍💻

打coding的奥特曼
打coding的奥特曼

Posted on

规范姓名格式

请把用户输入的不规范的英文名字,变为首字母大写,其他小写的规范名字。输入:['adam', 'LISA', 'barT'],输出:['Adam', 'Lisa', 'Bart']。

const list = ['adam', 'LISA', 'barT'];
const normalizeStr = str=>str.slice(0,1).toUpperCase()+str.slice(1).toLowerCase();
const normalize = list=>list.map(x => normalizeStr(x));
console.log(normalize(list));
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

👀 Just want to lurk?

 
That's fine, you can still create an account and turn on features like 🌚 dark mode.