basant307/AI_Governance_Project
048
1/**2 * Get the count of the longest repeating streak of `substring` in `value`.3 *4 * @param {string} value5 * Content to search in.6 * @param {string} substring7 * Substring to look for, typically one character.8 * @returns {number}9 * Count of most frequent adjacent `substring`s in `value`.10 */11export function longestStreak(value, substring) {12 const source = String(value)13 let index = source.indexOf(substring)14 let expected = index15 let count = 016 let max = 017 18 if (typeof substring !== 'string') {19 throw new TypeError('Expected substring')20 }21 22 while (index !== -1) {23 if (index === expected) {24 if (++count > max) {25 max = count26 }27 } else {28 count = 129 }30 31 expected = index + substring.length32 index = source.indexOf(substring, expected)33 }34 35 return max36}37 