Last active
October 12, 2015 12:54
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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