Home > Software design >  Why doesn't my Google Sheets word count custom function work?
Why doesn't my Google Sheets word count custom function work?

Time:05-13

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:

If this is a enter image description here

  • Related