-6

I'm wonder how can Google Spreadsheet give a similarity Score for 2 strings What I want is this : sample spreadsheet

I'm looking for a miracle to make Spreadsheet auto calculate Similarity score then fill in. I found a VBA code but don't know how to convert to GAS :( (i mentioned here : https://productforums.google.com/d/msg/docs/0zg-BV3KrHo/XInEthmHAwAJ) Any help would be greatly appreciated. Thanks and have a nice day !

Tim Williams
  • 154,628
  • 8
  • 97
  • 125
Linh
  • 1
  • 1

1 Answers1

0

This may get you pointed in the right direction.

function similar() {
  
    var a = "test";
    var b = "tes";
    var lengthA = a.length;
    var lengthB = b.length;
    var equivalency = 0;
    var minLength = (a.length > b.length) ? b.length : a.length;    
    var maxLength = (a.length < b.length) ? b.length : a.length;    
    for(var i = 0; i < minLength; i++) {
        if(a[i] == b[i]) {
            equivalency++;
        }
    }


    var weight = equivalency / maxLength * 100;
  Logger.log(weight)
}
OblongMedulla
  • 1,471
  • 9
  • 21
  • Hi, I tried your **Similar** fuction but it seems not work. I tried **=similar(A2;B2)** at the formular then enter , but the result is a blank cell. Sorry, i'm an accountant and have no coding skill :( – Linh May 11 '17 at 15:17
  • ahh I get that, SO is more for answering code related questions. You may need to hire a developer. – OblongMedulla May 11 '17 at 15:20