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

Function countCommonBigrams

String/DiceCoefficient.js:23–30  ·  view source on GitHub ↗
(bigrams, string)

Source from the content-addressed store, hash-verified

21// Calculate the number of common bigrams between a map of bigrams and a string
22
23function countCommonBigrams(bigrams, string) {
24 let count = 0
25 for (let i = 0; i < string.length - 1; i++) {
26 const bigram = string.substring(i, i + 2)
27 if (bigrams.has(bigram)) count++
28 }
29 return count
30}
31
32// Calculate Dice coeff of 2 strings
33function diceCoefficient(stringA, stringB) {

Callers 1

diceCoefficientFunction · 0.85

Calls 1

hasMethod · 0.45

Tested by

no test coverage detected