(string)
| 9 | |
| 10 | // Find the bistrings of a string and return a hashmap (key => bistring, value => count) |
| 11 | function 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 |
no test coverage detected