2

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.

AnWa
  • 21
  • 1
  • 3
    since this is a conceptual question it seems more appropriate for https://programmers.stackexchange.com/ – Gerald Schneider Apr 29 '15 at 08:37
  • Can you maybe give an example of what your array looks like at certain points and what kind of fingerprints you want to be created at those stages? – basilikum Apr 29 '15 at 09:04

2 Answers2

1

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
 }
flotto
  • 535
  • 5
  • 17
1

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

Community
  • 1
  • 1
symcbean
  • 47,736
  • 6
  • 59
  • 94