DIFFERENCE in JS

Description

Unfortunately, this functionality is not available in JS, but this can be implemented easily.

This functions requires the SOUNDEX algorithm implementation.

Sample Source Pattern

Implementation Example

function DIFFERENCE(strA, strB) {
    var count = 0;
    for (var i = 0; i < strA.length; i++){
       if ( strA[i] == strB[i] ) count++; 
    }
    
    return count;
}

Arguments

strA, strB: String expressions resulting by executing the SOUNDEX algorithm.

Return Type

String.

Examples

CREATE OR REPLACE FUNCTION SOUNDEX_DIFFERENCE(str_1 varchar, str_2 varchar)
  RETURNS string
  LANGUAGE JAVASCRIPT
AS
$$
    function DIFFERENCE(strA, strB) {
      var count = 0;
      for (var i = 0; i < strA.length; i++){
         if ( strA[i] == strB[i] ) count++; 
      }
    
    return count;
    }
    
    return DIFFERENCE(STR_1, STR_2);
$$;

SELECT SOUNDEX_DIFFERENCE(GET_SOUNDEX('two'), GET_SOUNDEX('too')) DIFFERENCE;

Last updated