Skip to content

Instantly share code, notes, and snippets.

@tuckcodes
Created December 22, 2018 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuckcodes/cdc691d498be28be53d2a691100d685b to your computer and use it in GitHub Desktop.
Save tuckcodes/cdc691d498be28be53d2a691100d685b to your computer and use it in GitHub Desktop.
Count the specific letter occurrence in a string with the string and letter being a parameter each
// Bean Counter
// Determine how many matching letters there are in an input string from an input character
function countChar(stringInput, charSelect) {
stringInput = String(stringInput);
let letterArray = Array.from(stringInput), count = 0;
letterArray.forEach(letter => {
if (letter == charSelect) {
count++;
};
});
return count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment