题解 | #统计字符#

统计字符

http://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5

const line = readline();

function func(line) {
    const map = {
        en: 0,
        space: 0,
        num: 0,
        other: 0
    };
    const arr = line.split('');
    
    arr.forEach((item) => {
        if (/^[A-Za-z]$/.test(item)) {
            map['en']++;
        } else if (item === ' ') {
            map['space']++;
        } else if (/^[0-9]$/.test(item)) {
            map['num']++;
        } else {
            map['other']++;
        }
    });
    
    for(let key in map) {
        print(map[key]);
    }
}

func(line);
全部评论

相关推荐

下个早班:秒挂就是不缺人
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务