I have been given an assignment where I need to count a specific letter in a string. However, the issue is that I am unsure of how to treat capital and lowercase letters as the same character. For example, if there are three instances of 'a' in the string 'aAa', my code needs to recognize them all.
Currently, my code works well when it can differentiate between capital and lowercase letters.
function countChar(string, char) {
var count = 0;
for (var i = 0; i < string.length; i++) {
if (string[i] === char) {
count = count + 1;
}
}
return count;
}