counting things in javascript
✓ Published0🌍 Public
Aamundo
Last edited Oct 19, 2014
Created on Oct 19, 2014
A short JavaScript snippet counts word frequencies from a fixed string of text, using the array `reduce` method to tally occurrences and building a plain object that maps each word to its count. The example demonstrates a minimal functional programming pattern for aggregating categorical data, with the source data being a literal sentence split into an array of words. The output is logged to the console, showing a frequency distribution where repeated words like “pease” and “porridge” appear with higher counts than unique terms. No external libraries are used; the code relies solely on native JavaScript array and object methods.
AI-generated description