Created
September 6, 2019 19:57
-
-
Save rafaelsq/6d8394e34d280b38fdf571ea08c817cd to your computer and use it in GitHub Desktop.
// ORP: Optimal Recgonition Point
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
// ORP: Optimal Recgonition Point | |
function getORPIndex(word) { | |
var length = word.length; | |
var lastChar = word[word.length - 1]; | |
if (lastChar == '\n') { | |
lastChar = word[word.length - 2]; | |
length--; | |
} | |
if (',.?!:;"'.indexOf(lastChar) != -1) length--; | |
return length <= 1 ? 0 : (length == 2 ? 1 : (length == 3 ? 1 : Math.floor(length / 2) - 1)); | |
} | |
"you should do it again and again for as much time as you needs!".split(" ") | |
.map(t => [i=getORPIndex(t), t]) | |
.map(i => "\033[30m ".slice(0,-(i[0]+1)) + i[1].slice(0, i[0]) + "\033[31m" + i[1][i[0]] + "\033[30m" + i[1].slice(i[0]+1)) | |
.map(t => console.log(t)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment