题解 | #统计字符#
统计字符
https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
代码简化成功!
const rl = require("readline").createInterface({ input: process.stdin, output: process.stdout }); rl.on('line', line => { let arr = [/[a-z]/ig, /\s/g, /[0-9]/g, /[^a-z0-9\s]/ig] for(let i = 0; i < arr.length; i++){ let res = line.match(arr[i]) ? line.match(arr[i]).join('').length : 0 console.log(res) } })