Guest User

Untitled

a guest
Jul 16th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. complexWordIdentification(text, words) {
  2. // list of "complex words"
  3. const complexWords = words;
  4. // array will be populated with results.
  5. const results = [];
  6. // loop through each complex word and see if it occurs in the text
  7. let match, regexp;
  8.  
  9. for (let i = 0; i < complexWords.length; i++) {
  10. // the complex word we are checking in this iteration
  11. const complexWord = complexWords[i];
  12. // the complex word we are checking in this iteration
  13. regexp = new RegExp(complexWord, 'g');
  14.  
  15. while ((match = regexp.exec(text)) !== null) {
  16. // the results object
  17. const result = {
  18. begin: (regexp.lastIndex - complexWords[i].length),
  19. end: regexp.lastIndex,
  20. text: complexWord
  21. };
  22. // add the object to the results array
  23. const index = results.length;
  24. results[index] = result;
  25. console.log(result);
  26. }
  27. }
  28. // return the results array when done
  29. return results;
  30. }
Add Comment
Please, Sign In to add comment