Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. // ORP: Optimal Recgonition Point
  2. function getORPIndex(word) {
  3. var length = word.length;
  4. var lastChar = word[word.length - 1];
  5. if (lastChar == '\n') {
  6. lastChar = word[word.length - 2];
  7. length--;
  8. }
  9. if (',.?!:;"'.indexOf(lastChar) != -1) length--;
  10. return length <= 1 ? 0 : (length == 2 ? 1 : (length == 3 ? 1 : Math.floor(length / 2) - 1));
  11. }
  12.  
  13. "you should do it again and again for as much time as you needs!".split(" ")
  14. .map(t => [i=getORPIndex(t), t])
  15. .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))
  16. .map(t => console.log(t))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement