Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. text = ''
  2. +'nAs I looked to the east right into the sun,'
  3. +'nI saw a tower on a toft worthily built;'
  4. +'nA deep dale beneath a dungeon therein,'
  5. +'nWith deep ditches and dark and dreadful of sight'
  6. +'nA fair field full of folk found I in between,'
  7. +'nOf all manner of men the rich and the poor,'
  8. +'nWorking and wandering as the world asketh.'
  9.  
  10. skipWords = ['the', 'and']
  11. curr = []
  12.  
  13. text.toLowerCase().replace(/bw{3,}b/g, function(word) {
  14. if (skipWords.indexOf(word) >= 0)
  15. return;
  16. var len = curr.length
  17. if (!len || curr[len - 1].charAt(0) == word.charAt(0))
  18. curr.push(word)
  19. else {
  20. if (len > 2)
  21. console.log(curr)
  22. curr = [word]
  23. }
  24. })
  25.  
  26. ["deep", "ditches", "dark", "dreadful"]
  27. ["fair", "field", "full", "folk", "found"]
  28. ["working", "wandering", "world"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement