動態庫的製作和使用
阿新 • • 發佈:2020-11-01
//這個我也一直在糾結,英文標題,即使是首字母大寫,也未必每一個單詞的首字母都是大寫的,但是又不知道哪些應該大寫,哪些不應該大寫 //ecDo.titleCaseUp('this is a title') //"This Is A Title" titleCaseUp: function (str, splitType) { var _splitType = splitType || /\s+/g; var strArr = str.split(_splitType), result = "", _this = this strArr.forEach(function (item) { result += _this.changeCase(item, 1) + ' '; }) return this.trim(result, 4) }
字串找出最長單詞
//ecDo.longestWord('Find the Longest word in a String') //result:7 //ecDo.longestWord('Find|the|Longest|word|in|a|String','|') //result:7 longestWord: function (str, splitType) { var _splitType = splitType || /\s+/g, _max= 0,_item=''; var strArr = str.split(_splitType); strArr.forEach(function (item) { if (_max < item.length) { _max = item.length _item=item; } }) return {el:_item,max:_max}; }