当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - How to "fuzzy" fingerprint an array

问题描述:

For my current project I need to find a way to "fuzzy" - fingerprint a javascript array client-side.

The problem is that the elements inside the array can change over time. By change I mean the order is stable but some elements may be removed and others my be included. Now I need to find a way that produces exactly the same fingerprint (within a given threshold).

I'm currently thinking about a kind of a partial match implementation but I'm curious how others would do it.

网友答案:

You could wrap your array into an object and add a modification counter to that object. On each array modification you must increment the modification counter. by defining a treshold for array modifications, you can make decisions.

var fuzzyArray = {
                   data : [],
                   modCount : 0,
                   changeElement : function (elementId, newData){
                                      data[elementid] = newData;
                                      modCount++;
                                   }
               };

 //adding some elements...

 fuzzyArray.changeElement(1,"foo");
 if (fuzzyArray.modCount > treshold){
     // do something
 }
网友答案:

It depends on what your definition of "fuzzy" is.

Filype's suggestion will give you a highly specific fingerprint. Nothing fuzzy about that.

One solution would be looking at the levenstein difference between the JSON representations of the test case and the reference data set (divide the score by the length of the reference set to get a proportion). A quick google found this implementation.

Alternatively you might simply do a count of the elements which are different

分享给朋友:
您可能感兴趣的文章:
随机阅读: