Created
July 9, 2018 18:18
-
-
Save rawnly/de08536f862e3f96a0af1ca706f99d6a to your computer and use it in GitHub Desktop.
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
const { readFileSync: readFile } = require('fs'); | |
const file = readFile('path-to-file', 'utf8'); | |
const WPM = 300; | |
const wordSpeed = wpm => 60000 / wpm; | |
const readText = (txt, wpm) => { | |
const words = txt.split(/\s+/).map(item => item.trim().replace(',', '')) | |
let i = 0; | |
let int = setInterval(function() { | |
console.clear(); | |
console.log(); | |
console.log(words[i]); | |
console.log(); | |
console.log('-'.repeat(5)); | |
console.log(`${wpm} wpm | ${wpm/60} wps | 1 word each ${wordSpeed(wpm)}ms | ${i+1} words read of ${words.length}`); | |
console.log(); | |
if ( i < words.length ) { | |
i++; | |
} else { | |
clearInterval(int); | |
setTimeout(() => { | |
console.clear() | |
console.log() | |
console.log(`${wpm} wpm | ${wpm/60} wps | 1 word each ${wordSpeed(wpm)}ms | ${i+1} words read of ${words.length}`); | |
}, 500) | |
} | |
}, wordSpeed(wpm)) | |
} | |
console.clear(); | |
console.log('Your challenge will start in...'); | |
setTimeout(() => { | |
let timerCount = 3; | |
let timer = setInterval(() => { | |
console.clear(); | |
console.log(); | |
console.log(`${timerCount}...`); | |
if ( timerCount === 0 ) { | |
clearInterval(timer); | |
} else { | |
timerCount--; | |
} | |
}, 1000) | |
setTimeout(() => { | |
readText(file, WPM); | |
}, 3000) | |
}, 500) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment