题解 | #统计字符#
统计字符
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);