题解 | #计算某字符出现次数#
计算某字符出现次数
http://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
解题思路
- 计算原字符串总长度
- 将“某字符”删除后,生成新的字符串
- 第一步 减去 第二步 的值,就是字符串出现的次数
function includLength(str,key) {
const strLength = str.length
const exp = new RegExp(key,'gi')
const newSrt = str.replace(exp,'')
return strLength - newSrt.length
}