常见词在不同领域中检测jquery [英] Common words detect in different fields jquery

查看:62
本文介绍了常见词在不同领域中检测jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在jquery中,您如何确定一个元素是否使用了另一个元素中使用的单词?例如:如果一个字段包含值:fishbucket,另一个字段包含fishdome,您将如何扫描两个字段以获取常用字,在这种情况下是鱼?或者甚至是数字,比如一个包含值12793的字段和另一个包含值93127的字段,公共数字是127.您是否需要列出常用单词并根据两个字段的值运行它?或者有没有办法确定常用单词而不运行每个确定的列表。我似乎无法找到起点,所以如果有人能给我一个开始的地方,那就太好了。

In jquery, how would you determine if one element uses a word that was being used in another element? For example: if one field contains the value: fishbucket, and another field contains fishdome, how would you scan the two fields to get the common word, in this case being fish? Or even with numbers, say one field containing the value 12793 and another containing the value 93127, common number being 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 determine the common word without running a per-determined list. I can't seem to find the starting point, so if anyone can give me a place to start, it would be great.

推荐答案

不需要jquery。简单的javascript就可以了。我只能给你一个函数来找到最常见的起始字符串。

No need for jquery. Simple javascript will do. I can only give you a function to find longest in common starting string.

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);
}

例如

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

将产生'测试'

生物信息学中用于此类事情的标准工具是 BLAST 计划。它用于比较分子的两个片段(如DNA或蛋白质),以找到它们彼此对齐的位置 - 基本上两个字符串(有时大小为多GB)共享共同的子串。

The standard tool for doing this sort of thing in Bioinformatics is the BLAST program. It is used to compare two fragments of molecules (like DNA or proteins) to find where they align with each other - basically where the two strings (sometimes multi GB in size) share common substrings.

这篇关于常见词在不同领域中检测jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆