Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function findOccurences(sentence, word){
- let regex = new RegExp(`\b${word}\b`, 'ig'); //case-insensitive and global flags
- console.log(sentence.match(regex).length);
- }
- findOccurences('The waterfall was so high, that the child couldn’t see its peak.', 'the');
- findOccurences('How do you plan on achieving that? How? How can you even think of that?', 'how');
- findOccurences('There was one. Therefore I bought it. I wouldn’t buy it otherwise.', 'there');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement