/**
* Return the number of occurances of the search character in the target string.
*
* @param target String to search.
* @param search Character to search string for.
*
* @throws {Error} If search params is not exactly one character.
*
* @example
* strCount('Hello', 'o') // => 1
* strCount('Hello', 'l') // => 2
* strCount('', 'z') // => 0
*/functionstrCount(target:string,search:string):number{if(!search||search.length!==1){thrownewError('Search character be exactly one character');}return(target.match(newRegExp(search,'g'))||[]).length;}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
TypeScript