Leetcode-Detect Capital

 

该题意思是判断一个字符串,如果全部是大写或全部是小写再或者只有首字母是大写则返回true,其余返回false;

 

 

 1 /**
 2  * @param {string} word
 3  * @return {boolean}
 4  */
 5 var detectCapitalUse = function(word) {
 6     var thisWord = word;
 7     var length = thisWord.length;
 8     var thisWordUpper = thisWord.toUpperCase();
 9     var thisWordLower = thisWord.toLowerCase();
10     var thisWordFirst = thisWord.substr(0, 1);
11     var thisWordOther = thisWord.substr(1,length-1);
12     if((thisWord ==thisWordUpper)||(thisWord == thisWordLower)){
13         return true;
14     }else if((thisWordFirst == thisWordFirst.toUpperCase())&&(thisWordOther == thisWordOther.toLowerCase())){
15         return true;
16     }else{
17         return false;
18     }
19 };

 

posted @ 2017-02-19 21:33  徐大卷子  阅读(283)  评论(0编辑  收藏  举报