Skip to content

Instantly share code, notes, and snippets.

@felquis
Last active March 18, 2017 06:15
Show Gist options
  • Select an option

  • Save felquis/e547ef0db08df8c453608de7e5a45c7d to your computer and use it in GitHub Desktop.

Select an option

Save felquis/e547ef0db08df8c453608de7e5a45c7d to your computer and use it in GitHub Desktop.

Revisions

  1. felquis revised this gist Mar 18, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions estimate-reading-time.js
    Original file line number Diff line number Diff line change
    @@ -4,10 +4,10 @@ document.body.innerText.split(' ')
    .map((split) => split.replace(/[^a-zZ-a]+/g, ''))
    .filter((split) => split.length > 1)
    .reduce((acc, split) => {
    const time = split.split('').length * 70
    return [...acc, (time < 400) ? time : 400]
    const time = split.split('').length * 115
    return [...acc, (time > 500) ? time : 500]
    }, [])
    .reduce((acc, time) => ([acc[0] + time]), [0])
    .map((time) => time / 1000 / 60)
    .map((time) => (time / 1000 / 60))

    // instead of using document.body, you can select only the main content of your page
  2. felquis created this gist Mar 18, 2017.
    13 changes: 13 additions & 0 deletions estimate-reading-time.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    // output is in minutes
    document.body.innerText.split(' ')
    .filter((split) => split.length > 1)
    .map((split) => split.replace(/[^a-zZ-a]+/g, ''))
    .filter((split) => split.length > 1)
    .reduce((acc, split) => {
    const time = split.split('').length * 70
    return [...acc, (time < 400) ? time : 400]
    }, [])
    .reduce((acc, time) => ([acc[0] + time]), [0])
    .map((time) => time / 1000 / 60)

    // instead of using document.body, you can select only the main content of your page