Count the number of occurrences of a given substring in a string
Count the number of occurrences of a given substring in a string function COUNT_SUBSTR(str,sbStr){ let count = 0; let pos = str.indexOf(sbStr); while (pos !== -1){ count++; pos = str.indexOf(sbStr,pos+1); } return count; } The provided code defines a function called COUNT_SUBSTR that takes two parameters: str and sbStr. The purpose of this function is … Read more