码迷,mamicode.com
首页 > 其他好文 > 详细

首字母变大写脚本

时间:2017-02-04 14:26:07      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:art   大写   substring   英文名   upper   ict   bst   tostring   用户输入   

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

 1 ‘use strict‘;
 2 
 3 function normalize(arr) {
 4 return arr.map(function(x){ return x.toLowerCase();}).map(function(x){ return x[0].toUpperCase() + x.substring(1, x.length)}) 
 5 }
 6 
 7 // 测试:
 8 if (normalize([‘adam‘, ‘LISA‘, ‘barT‘]).toString() === [‘Adam‘, ‘Lisa‘, ‘Bart‘].toString()) {
 9     alert(‘测试通过!‘);
10 }
11 else {
12     alert(‘测试失败!‘);
13 }

 

首字母变大写脚本

标签:art   大写   substring   英文名   upper   ict   bst   tostring   用户输入   

原文地址:http://www.cnblogs.com/python3-study/p/6364273.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!