Skip to content

Instantly share code, notes, and snippets.

@cezarneaga
Created July 9, 2018 20:16
Show Gist options
  • Save cezarneaga/56e5b19f29d8adf1d0d75f3e54a23819 to your computer and use it in GitHub Desktop.
Save cezarneaga/56e5b19f29d8adf1d0d75f3e54a23819 to your computer and use it in GitHub Desktop.
display approximate reading time
countWords = text => {
return text.split(/\s+/).length
}
const words = this.countWords(article.body)
const readTime = Math.round(words / 250)
const minutes = readTime === 1 ? 'minute' : 'minutes'
//Render this
Aproximately {readTime} {minutes}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment