Skip to content

Instantly share code, notes, and snippets.

@TimBlock
Created January 14, 2016 08:20
Show Gist options
  • Select an option

  • Save TimBlock/5981a76396e07f22a991 to your computer and use it in GitHub Desktop.

Select an option

Save TimBlock/5981a76396e07f22a991 to your computer and use it in GitHub Desktop.
function countBs(word){
var sum=0;
for( var i = 0; i < word.length; i++){
if (word.charAt(i)==="B") sum++;
};
console.log(sum);
};
function countChar(word, index){
var sum=0;
for( var i = 0; i < word.length; i++){
if (word.charAt(i)===index) sum++;
};
console.log(sum);
};
console.log(countBs("BBC"));
// 2
console.log(countChar("kakkerlak", "k"));
// → 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment