MCPcopy Create free account
hub / github.com/TheAlgorithms/JavaScript / diceCoefficient

Function diceCoefficient

String/DiceCoefficient.js:33–48  ·  view source on GitHub ↗
(stringA, stringB)

Source from the content-addressed store, hash-verified

31
32// Calculate Dice coeff of 2 strings
33function diceCoefficient(stringA, stringB) {
34 if (stringA === stringB) return 1
35 else if (stringA.length < 2 || stringB.length < 2) return 0
36
37 const bigramsA = mapBigrams(stringA)
38
39 const lengthA = stringA.length - 1
40 const lengthB = stringB.length - 1
41
42 let dice = (2 * countCommonBigrams(bigramsA, stringB)) / (lengthA + lengthB)
43
44 // cut 0.xxxxxx to 0.xx for simplicity
45 dice = Math.floor(dice * 100) / 100
46
47 return dice
48}
49
50export { diceCoefficient }

Callers 1

Calls 2

mapBigramsFunction · 0.85
countCommonBigramsFunction · 0.85

Tested by

no test coverage detected