13 lines
275 B
JavaScript
13 lines
275 B
JavaScript
const word_count = function (text) {
|
||
const text_list = text.replace(/[、\r?\n,,\s]+/g, " ").split(" ");
|
||
let word_obj = {};
|
||
for (const word of text_list) {
|
||
word_obj[word] = (word_obj[word] || 0) + 1;
|
||
}
|
||
return word_obj;
|
||
};
|
||
|
||
module.exports = {
|
||
word_count,
|
||
};
|