Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function countLetterOccurence(str, letter) {
- const reg = str.match(new RegExp(letter, 'g'));
- return (reg ? reg : []).length;
- }
- const text = 'Hey my name is Eric, Im a front-end developer and mostly do my work on a laptop';
- console.log(`Letter a is mentioned $(countLetterOccurence(text, 'a')} times`);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement