Skip to content

Instantly share code, notes, and snippets.

@dyaa
Last active October 12, 2015 12:54
Show Gist options
  • Save dyaa/73ea6689f5cd87b83e5d to your computer and use it in GitHub Desktop.
Save dyaa/73ea6689f5cd87b83e5d to your computer and use it in GitHub Desktop.
Medium-like Estimated Reading Time The code is pretty simple. It assumes you read at 200 words per minute. If the text is under 200 words, it’ll just say it’s a one minute read.
var readTime = function(text){
var regex = /(<([^>]+)>)/ig;
var minutes = Math.floor(text.trim().replace(regex, ' ').split(' ').length / 200 )
if(minutes === 0) minutes = 1
return minutes + ' min read'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment