1function count(str, find) {
2 return (str.split(find)).length - 1;
3}
4
5count("Good", "o"); // 2
1function countOccurences(string, word) {
2 return string.split(word).length - 1;
3}
4var text="We went down to the stall, then down to the river.";
5var count=countOccurences(text,"down"); // 2
1 function countInstancesOf(letter, sentence) {
2 var count = 0;
3
4 for (var i = 0; i < sentence.length; i++) {
5 if (sentence.charAt(i) === letter) {
6 count += 1;
7 }
8 }
9 return count;
10}