JSFiddle - React, Tailwind, and code Playground

by fairmutex

JavaScript

function countB(s){
    var acc = 0;
    for(i = 0 ; i < s.length;i++){
        acc += (s.charAt(i) == "B"?1:0)
    }
    return acc;
}


function countChar(s,c){
     var acc = 0;
    for(i = 0 ; i < s.length;i++){
        acc += (s.charAt(i) == c?1:0)
    }
    return acc;
}

function newCountB(s){
    return countChar(s,"B");
}

console.log(countB("ABBARbSTDGBBSFSDFB"));
console.log(countChar("ABBARbSTDGBBSFSDFB",'S'));
console.log(newCountB("ABBARbSTDGBBSFSDFB"));