Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. function countLetterOccurence(str, letter) {
  2. const reg = str.match(new RegExp(letter, 'g'));
  3. return (reg ? reg : []).length;
  4. }
  5.  
  6. const text = 'Hey my name is Eric, Im a front-end developer and mostly do my work on a laptop';
  7. console.log(`Letter a is mentioned $(countLetterOccurence(text, 'a')} times`);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement