CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
index.js28 linesDownload Raw Back to ccount
1/**2 * Count how often a character (or substring) is used in a string.3 *4 * @param {string} value5 *   Value to search in.6 * @param {string} character7 *   Character (or substring) to look for.8 * @return {number}9 *   Number of times `character` occurred in `value`.10 */11export function ccount(value, character) {12  const source = String(value)13 14  if (typeof character !== 'string') {15    throw new TypeError('Expected character')16  }17 18  let count = 019  let index = source.indexOf(character)20 21  while (index !== -1) {22    count++23    index = source.indexOf(character, index + character.length)24  }25 26  return count27}28