Skip to content

Added word count operation #2039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Added word count operation #2039

wants to merge 3 commits into from

Conversation

sw5678
Copy link
Member

@sw5678 sw5678 commented May 12, 2025

Added a word count operation that will count the words in the input field and then output a css with the count of each word.

for (let j = 0; j < inputArray.length; j++) {

// Trim whitespace and replace punctuation
const word = inputArray[j].replace(/(?:!|"|#|\$|%|&|\(|\)|\*|\+|,|-|\.|\/|:|;|<|=|>|\?|@|\[|\\|\]|\^|_|`|\{|\||\}|~|£)/g, "").trim();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regular expression can be written as:

/[!"#....£]/g

Which will be easier to read.


// Process output to string
let output = "WORD,COUNT\n";
for (let k = 0; k < order.length; k++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a oneliner might be easier here:

order.map(entry => `${entry},${counter[entry]}`).join('\n')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants