Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function countSubstringOccur(array) {
- var keywordLength = array[0].length;
- var textLength = array[1].length;
- var keyword = array[0];
- var text = array[1];
- var firstSymbol = keyword[0];
- var counter = 0;
- for (var i = 0; i < textLength; i++) {
- if (text[i] === firstSymbol) {
- var count = 0;
- for (var j = i; j < keywordLength; j++) {
- if (keyword[j - i] === text[j]) {
- count++;
- if (count === keywordLength) {
- counter++;
- }
- }
- }
- }
- }
- return counter;
- }
- 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