Advertisement
braveheart1989

findOccOfWordInSentence

Oct 6th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function findOccOfWordInSentence ([text,word]) {
  2.     [text, word] = [text, word];
  3.     text = text.toLowerCase ();
  4.     let regex = new RegExp ('\\b' + word + '\\b', 'ig');
  5.     let match = text.match (regex);
  6.  
  7.     if (match != null) {
  8.         console.log (match.length);
  9.     }
  10. }
  11. findOccOfWordInSentence (
  12.     [
  13.         "How do you plan on achieving that? How? How can you even think of that?",
  14.         "how"
  15.  
  16.     ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement