Common words found in different jquery fields

In jquery, how would you determine if one element uses a word that is used in another element? For example: if one field contains the value: fishbucket and the other field contains fishdome, how would you scan two fields to get a common word, in this case being a fish? Or even with numbers, say, one field containing the value 12793, and another containing the value 93127, the total number is 127. Would you need to make a list of common words and run it against the values ​​of both fields? Or is there a way to define a common word without starting a specific list. I can't seem to find a starting point, so if anyone could give me a place to start, it would be great.

+4
source share
3 answers

No need for jquery. Simple javascript will do. I can only give you a function to find the longest common start line.

function commonStart(array){ var x = array.slice(0).sort(), word1 = x[0], word2 = x[x.length-1], i= 0; while(word1.charAt(i) == word2.charAt(i)) ++i; return word1.substring(0, i); } 

eg.

 var testArray = ['testone','testtwo','testthree']; commonStart(testArray); 

will give 'test'

The standard tool for this kind of thing in Bioinformatics is the BLAST program. It is used to compare two fragments of molecules (for example, DNA or proteins) to find where they align with each other - basically, where two lines (sometimes several GB in size) have common substrings.

0
source

List all the values ​​in your form first.

 var inputvalue = []; //array declaration $('input[type=text]').each(function(){ inputvalue.push($(this).val()); //saves value in array }); 

then swipe all the values ​​to get a common string matching the pattern you need to determine the overall string sequence how many characters are longer.

0
source

The problem can be broken down into the search for the longest common subsequence.

Here the javascript implementation for LCS search consisted of two words. What you need to do is click all the words in the array, and then call LCS for every 2 lines you want to compare. (If the return length is> 1, there is a common text between them).

There are several string matching algorithms (based on hashes), you might also want to use them on Google. Use only if the requirement is large, for normal cases, the LCS implementation should be sufficient.

0
source

Source: https://habr.com/ru/post/1501240/


All Articles