Last active
January 16, 2021 11:40
-
-
Save borgateo/3a39b02839d84f249311 to your computer and use it in GitHub Desktop.
reading time
This file contains hidden or 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
/* | |
** readingTime | |
** =========== | |
** Given a string, it returns the time a human needs to read it | |
** @param {String} text - the string to analyze | |
** @param {Number} wpm - words per minute | |
*/ | |
function readingTime( text, wpm ) { | |
if ( !text ) text = ''; | |
var words = text.trim().split(/\s+/g).length; | |
var wps = ( wpm || 210 ) / 60; | |
var rts = words / wps; | |
var m = Math.floor( rts / 60 ); | |
var s = Math.round( rts - m * 60 ); | |
return( { | |
minutes: m, | |
seconds: s | |
} ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment