Complete the JavaScript function to count the number of substrings in a given string that contain exactly k distinct characters. The function takes two parameters: a string and an integer. The str
contains only lowercase alphabets. It should return the count of substrings with exactly k distinct characters.
For example: