题解 | 计算某字符出现次数
计算某字符出现次数
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void async function () {
// Write your code here
const theString = await readline()//入参一,字符串;
const theInput = await readline()//入参二,单个字符;
let theLength = 0
for(let index = 0; index<theString.length;index++){
//判断是否符合题目要求;如果不允许使用正则,则用哈希表来处理。单个字符全等于其字身,或者等于它自己。如theString[index]===({a:A,b:B})[theInput] 或 theString[index]===theInput。
if(new RegExp(`^${theInput}$`,'i').test(theString[index])){
theLength = theLength + 1
}
}
console.log(theLength)
}()
