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

Function mapBigrams

String/DiceCoefficient.js:11–19  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

9
10// Find the bistrings of a string and return a hashmap (key => bistring, value => count)
11function mapBigrams(string) {
12 const bigrams = new Map()
13 for (let i = 0; i < string.length - 1; i++) {
14 const bigram = string.substring(i, i + 2)
15 const count = bigrams.get(bigram)
16 bigrams.set(bigram, (count || 0) + 1)
17 }
18 return bigrams
19}
20
21// Calculate the number of common bigrams between a map of bigrams and a string
22

Callers 1

diceCoefficientFunction · 0.85

Calls 2

getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected