Created
January 11, 2018 14:23
-
-
Save bjyurkovich/0dcde76684da89b19a097f4c2df113ad to your computer and use it in GitHub Desktop.
search.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // terms = [text entered into box] | |
| // indices = [] | |
| // for current_index in range(0,len(all_indices)): | |
| // for term in terms.split(" "): | |
| // if term in entry: | |
| // indices.append(current_index) | |
| // return indices | |
| function independent_set_search(string_to_search, search_string) { | |
| let array_to_search = string_to_search.split(" "); | |
| let array_search_string = search_string.split(" "); | |
| // create result array of all false | |
| let is_relevant_array = array_search_string.map(item => { | |
| return false; | |
| }); | |
| // split up search terms and see if all terms match somewhere in provided content | |
| for (let i = 0; i < array_to_search.length; i++) { | |
| for (let j = 0; j < array_search_string.length; j++) { | |
| if (array_to_search[i].indexOf(array_search_string[j]) > -1) { | |
| is_relevant_array[j] = true; | |
| } | |
| } | |
| } | |
| // if any are false, return false...means that there is not content | |
| for (let k = 0; k < is_relevant_array.length; k++) { | |
| if (is_relevant_array[k] == false) { | |
| return false; | |
| } | |
| } | |
| // all were true, so return | |
| return true; | |
| } | |
| content = "There is a fox in the barn"; | |
| search = "fox barn"; | |
| let result = independent_set_search(content, search); | |
| console.log("should by true: ", result); | |
| search = "fox house"; | |
| result = independent_set_search(content, search); | |
| console.log("should be false: ", result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment