What is the result of the following code?
function countCharacters(str, char) {
if (str.length === 0) {
return 0;
}
return (str[0] === char ? 1 : 0) + countCharacters(str.slice(1), char);
}
console.log(countCharacters("abracadabra", "a"));
What is the result of the following code?
function countCharacters(str, char) {
if (str.length === 0) {
return 0;
}
return (str[0] === char ? 1 : 0) + countCharacters(str.slice(1), char);
}
console.log(countCharacters("abracadabra", "a"));