Advertisement
aslv

Substring Count

Jul 18th, 2014
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var input = [
  2.     ['in', 'We are living in a yellow submarine. We don\'t have anything else. Inside the submarine is very tight. So we are drinking all the day. We will move out of it in 5 days.'],
  3.     ['your', 'No one heard a single word you said. They should have seen it in your eyes. What was going around your head.'],
  4.     ['but', 'But you were living in another world tryin\' to get your message through.']
  5. ];
  6.  
  7. function countSubstringOccur(value) {
  8.     var delim = value[0];
  9.     var text = value[1];
  10.     var regex = new RegExp(delim, 'gi');
  11.     //console.log(text.match(regex));
  12.     var occurencesCount = (text.match(regex) || []).length;
  13.     console.log(occurencesCount);
  14. }
  15.  
  16. input.forEach(countSubstringOccur);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement