Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function searchSubstring()
- {
- var haystack = "We are living in an 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.";
- var needle = document.getElementById("problem3").value;
- //case insensitive
- haystack = haystack.toLowerCase();
- needle = needle.toLowerCase();
- var count = 0;
- var index = haystack.indexOf(needle);
- if (index >= 0) {
- count++;
- }
- while ((index = haystack.indexOf(needle, index+1)) && index != -1)
- {
- count++;
- }
- cons.innerHTML = count;
- }
Advertisement
Add Comment
Please, Sign In to add comment