I have the following function
function wordCount(input) {
const count = {};
input
.forEach(r => {
const words = r.split(" ")
words.forEach(w => {
w = w.replace(/[^a-zöüßä ]/i,"")
w = w[0].toUpperCase() w.slice(1).toLocaleLowerCase();
count[w] = (count[w] || 0) 1
})
})
const res = []
for(const [word,frequency] of Object.entries(count)) {
res.push([word,frequency])
}
return res;
}
I want to pass a column of sentences to the function, and it should return a row with two cells.
One with a unique word and the next with it's frequency in the sentences.
When using this function iv'e made I just get r.split
is not a function. Can anyone figure out why?
CodePudding user response: