Write JavaScript function that counts how many times a string occurs in a given text. Overlapping strings are allowed.
The input comes as two string arguments:
-
The first element is the target string
-
The second element is the text in which to search for occurrences.
Examples:
Input:
'the', 'The quick brown fox jumps over the lay dog.'
Output:
1
Input:
'ma', 'Marine mammal training is the training and caring for marine life such as, dolphins, killer whales, sea lions, walruses, and other marine mammals. It is also a duty of the trainer to do mental and physical exercises to keep the animal healthy and happy.'
Output:
7
The output should be a number, printed on the console.