Skip to content

Instantly share code, notes, and snippets.

@rafaelsq
Created September 6, 2019 19:57
Show Gist options
  • Save rafaelsq/6d8394e34d280b38fdf571ea08c817cd to your computer and use it in GitHub Desktop.
Save rafaelsq/6d8394e34d280b38fdf571ea08c817cd to your computer and use it in GitHub Desktop.
// ORP: Optimal Recgonition Point
// 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