Files
Course/Server/2/utils.js
2025-11-07 18:39:29 +08:00

13 lines
275 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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,
};