标签:rev 复杂 substr 试题 lse case testing 单词 文本
/** * 1. 从文本中找出单词的首字母并互换大小写(data 为示例数据结构, 实际可能更复杂) */ (function () { let data = "this is A string for Testing"; function findAndReverse(data) { let str = data.split(‘ ‘); for (let i = 0; i < str.length; i++) { if (str[i][0] >= ‘a‘ && str[i][0] <= ‘z‘) { str[i] = str[i][0].toUpperCase() + str[i].substring(1, str[i].length); } else if (str[i][0] >= ‘A‘ && str[i][0] <= ‘Z‘) { str[i] = str[i][0].toLowerCase() + str[i].substring(1, str[i].length); } } let arr = str.join(‘ ‘); console.log(arr) } findAndReverse(data) })();
标签:rev 复杂 substr 试题 lse case testing 单词 文本
原文地址:https://www.cnblogs.com/yyh28/p/12076430.html