Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- complexWordIdentification(text, words) {
- // list of "complex words"
- const complexWords = words;
- // array will be populated with results.
- const results = [];
- // loop through each complex word and see if it occurs in the text
- let match, regexp;
- for (let i = 0; i < complexWords.length; i++) {
- // the complex word we are checking in this iteration
- const complexWord = complexWords[i];
- // the complex word we are checking in this iteration
- regexp = new RegExp(complexWord, 'g');
- while ((match = regexp.exec(text)) !== null) {
- // the results object
- const result = {
- begin: (regexp.lastIndex - complexWords[i].length),
- end: regexp.lastIndex,
- text: complexWord
- };
- // add the object to the results array
- const index = results.length;
- results[index] = result;
- console.log(result);
- }
- }
- // return the results array when done
- return results;
- }
Add Comment
Please, Sign In to add comment