On many new blog and news sites, sorry not my blog, they have a ‘how long does this article take to read’ feature. This recently came up on an internal experiment and thought it would be fun to share the results.

From readingsoft.com

If top readers read at speeds of above 1000 words per minute (wpm) with near 85% comprehension, they only represent 1% of readers. Average readers are the majority and only reach around 200 wpm with a typical comprehension of 60%.

To offer a time-to-read feature on an article, we first need the text of the article contents. You may need to strip out any unnecessary garbage, such as html tags if you’re parsing the content in JavaScript after it’s on the page. Here’s a regular expression that will remove the html tags and leave you with just the words. Note that the /i and g allow it to catch all instances of the tags and ignore case. You can then split the words on space and get the number of words (length of array). Lastly, divide that count by the number of words the average reader can read (referenced from readingsoft.com) of 200 words per minute. Here’s the code that corresponds with that flow.

var articleContent =
  "<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Illo, ducimus similique! Vel deserunt incidunt optio esse sunt est et, maiores delectus voluptatibus debitis harum voluptatum obcaecati! Asperiores aut cumque ut!</p>";
articleContent = articleContent.replace(/(<([^>]+)>)/gi);
var timeToRead = Math.round(
  articleContent.split(" ").length / WORDS_PER_MINUTE
timeToRead = timeToRead <= 0 ? 1 : timeToRead;
var timeToReadMessage = "Time to read: " + timeToRead + " minute" + (timeToRead == 1 ? "" : "s");

Photo by Valentin on Unsplash