Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function countSubstringOccur(value) {
- var keyword = value[0];
- var text = value[1];
- var index = 0,
- count = 0;
- while(true) {
- var nextIndex = value.indexOf(keyword, index);
- if (nextIndex !== -1) {
- index = index + 1;
- count += 1;
- }
- else {
- break;
- }
- }
- return count;
- }
- console.log(countSubstringOccur(['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."]));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement