Skip to content

Instantly share code, notes, and snippets.

@alexpana
Created July 10, 2018 16:14
Show Gist options
  • Save alexpana/e924e5e2b61fd28f0d24a1120d0a38ef to your computer and use it in GitHub Desktop.
Save alexpana/e924e5e2b61fd28f0d24a1120d0a38ef to your computer and use it in GitHub Desktop.
estimate read time of article in JS
WPM = 200; m = Array.from(document.getElementsByTagName("p")).reduce((acc, t) => acc + t.innerHTML, "").split(" ").length / WPM; h = Math.floor(m / 60); m = Math.floor(m % 60); msg = h > 0 ? h+"h "+m+"m" : m+"m";alert("Estimated read time: " + msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment