Created
December 22, 2018 07:10
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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