Guest User

Untitled

a guest
Jan 14th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. removeLastSentence = (text) ->
  2. lastSeparator = Math.max(
  3. text.lastIndexOf("."),
  4. text.lastIndexOf("!"),
  5. text.lastIndexOf("?")
  6. )
  7.  
  8. revtext = text.split('').reverse().join('')
  9. sep = revtext.search(/[A-Z]\s+(\")?[\.\!\?]/)
  10. lastTag = text.length-revtext.search(/\/\</) - 2
  11. lastPtr = if (lastTag > lastSeparator) then (lastTag) else (text.length)
  12.  
  13. if sep > -1
  14. text1 = revtext.substring(sep+1, revtext.length).trim().split('').reverse().join('')
  15. text2 = text.substring(lastPtr, text.length).replace(/['"]/g,'').trim()
  16. sWithoutLastSentence = text1 + text2
  17. else
  18. sWithoutLastSentence = ''
  19. return sWithoutLastSentence
Add Comment
Please, Sign In to add comment