Question: JavaScript /* Implement a proximity search method. Given text as input, two keywords and a numeric range, return the number of times both keyword 1
JavaScript
/* Implement a proximity search method. Given text as input, two keywords and a numeric range, return the number of times both keyword 1 and keyword 2 are found within the given range throughout the text, or 0 if your search is not successful. The keywords themselves are considered to be part of the range. This makes 2 the minimum valid range for keyword proximity. For simplicity, assume all words are separated with a whitespace. input text(text) : The early bird gets the worm keyword1(text): bird keyword2(text): worm range(number) : 4 k1= bird k2 = worm text: the early bird bird worm worm gets the worm the early bird bird - 0 early bird bird worm - 2 bird = 2, worm = 1 -> 2 bird bird worm worm - 2 bird = 2, worm = 1 (as new word is same as old - neglect one word) -> 2 bird worm worm gets -0 bird = 0, worm = 0 as all are already processed worm worm gets the - 0 worm gets the worm - 0 */
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
