Writing advice

| | [C]olor

A common writing tip is to use short sentences and paragraphs. But do good writers follow such rule? That can be answered with Javascript:

numberOfSentences = (elm) => (elm.textContent.match(/([.?!]\s|.$)/g) || [] ).length
average = (arr) => arr.reduce((a, b) => a + b) / arr.length;

This calculates the average number of setences per paragraph in a website. Sample usage:

elms = Array.from(document.getElementsByTagName('p'))
average(elms.map(elm => numberOfSentences(elm)).filter(item => item !== 0))

After analysing some blog posts and news articles I found that the average paragraph is 2 to 3 sentences long. But my favorite writing advice is to focus on providing value to readers. Use the other writing tips to maximize that value.